mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 01:02:51 +08:00
Refactor notifications localStorage
cache into adapter pattern.
Sometimes you want stale data right away, then refresh it async. This adds `findStale` to the store for that case. If it returns an object with `hasResults` you can get the `results` and display them. It also returns a `refresh()` method to freshen up the stale data. To enable `localStorage` support for stale data, just include the mixin `StaleLocalStorage` into an adapter for that model. This commit includes a sample of doing that for `Notifications`.
This commit is contained in:
@ -63,6 +63,17 @@ test('find with query param', function() {
|
||||
});
|
||||
});
|
||||
|
||||
test('findStale with no stale results', (assert) => {
|
||||
const store = createStore();
|
||||
const stale = store.findStale('widget', {name: 'Trout Lure'});
|
||||
|
||||
assert.ok(!stale.hasResults, 'there are no stale results');
|
||||
assert.ok(!stale.results, 'results are present');
|
||||
return stale.refresh().then(function(w) {
|
||||
assert.equal(w.get('firstObject.id'), 123, 'a `refresh()` method provides results for stale');
|
||||
});
|
||||
});
|
||||
|
||||
test('update', function() {
|
||||
const store = createStore();
|
||||
return store.update('widget', 123, {name: 'hello'}).then(function(result) {
|
||||
@ -134,3 +145,4 @@ test('findAll embedded', function(assert) {
|
||||
assert.equal(fruits.objectAt(2).get('farmer.name'), 'Luke Skywalker');
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user