Skip to content

Commit

Permalink
fix(store): use GC for store.clear() when clearValue is set
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed Jul 11, 2023
1 parent d1fd7f1 commit b7aea14
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/store/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 });
}
}

Expand Down
4 changes: 3 additions & 1 deletion test/spec/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => [
Expand Down

0 comments on commit b7aea14

Please sign in to comment.