Skip to content

Commit

Permalink
Fixed initial value persistence in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
smikhalevski committed Jun 17, 2024
1 parent 1c6dff6 commit e37fe9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/main/plugin/synchronizeStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ export default function synchronizeStorage<Value = any>(
case 'fulfilled':
case 'rejected':
case 'invalidated':
if (!executor.isActive) {
break;
}
const stateStr = serializer.stringify(executor.toJSON());

if (latestStateStr !== stateStr) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/plugin/synchronizeStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ describe('synchronizeStorage', () => {
);
});

test('sets storage item to the initial value', () => {
const executor = manager.getOrCreate('xxx', 'aaa', [synchronizeStorage(localStorage)]);

expect(executor.value).toBe('aaa');
expect(localStorage.getItem('"xxx"')).toBe(
'{"key":"xxx","isFulfilled":true,"value":"aaa","annotations":{},"settledAt":50,"invalidatedAt":0}'
);
});

test('does not set storage item or resolve an executor if an executor is pending', async () => {
const executor = manager.getOrCreate('xxx', undefined, [
executor => {
Expand Down

0 comments on commit e37fe9e

Please sign in to comment.