diff --git a/docs/store/usage.md b/docs/store/usage.md index 6617db43..dc05b3b3 100644 --- a/docs/store/usage.md +++ b/docs/store/usage.md @@ -248,7 +248,7 @@ define({ #### Garbage Collector -The `store.clear()` method works as a garbage collector for unused model instances. Those that are not a dependency of any component connected to the DOM will be deleted entirely from the cache registry (as they would never exist) protecting from the memory leaks. It means, that even if you set `clearValue` to `false`, those instances that are not currently attached to the components, will be permanently deleted when the `store.clear()` method is invoked. +The `store.clear()` method can work as a garbage collector for unused model instances. Those that are not a dependency of any component connected to the DOM can be deleted entirely from the cache registry (as they would never exist) protecting from the memory leaks. If you set `clearValue` to `true`, those instances that are not currently attached to the components, will be permanently deleted when the `store.clear()` method is invoked. ## Factory diff --git a/src/store.js b/src/store.js index a5525e21..dd621a94 100644 --- a/src/store.js +++ b/src/store.js @@ -1303,7 +1303,7 @@ function clear(model, clearValue = true) { if (offline) offline.set(model.id, null); invalidateTimestamp(model); - cache.invalidate(config, model.id, { clearValue, deleteEntry: true }); + cache.invalidate(config, model.id, { clearValue, deleteEntry: clearValue }); } else { if (!configs.get(model) && !lists.get(model[0])) { throw Error( @@ -1317,7 +1317,7 @@ function clear(model, clearValue = true) { if (offline) offline.set(entry.key, null); if (entry.value) invalidateTimestamp(entry.value); } - cache.invalidateAll(config, { clearValue, deleteEntry: true }); + cache.invalidateAll(config, { clearValue, deleteEntry: clearValue }); } } diff --git a/test/spec/store.js b/test/spec/store.js index b41230eb..18989690 100644 --- a/test/spec/store.js +++ b/test/spec/store.js @@ -2696,7 +2696,9 @@ describe("store:", () => { value: "", [store.connect]: { get: (id) => - Promise.resolve().then(() => ({ id, value: Date.now() })), + new Promise((resolve) => + setTimeout(() => resolve({ id, value: Date.now() }), 5), + ), set: (id, values) => Promise.resolve().then(() => values), list: () => Promise.resolve().then(() => [