Skip to content

Commit

Permalink
Merge pull request #229 from effector/fix-combineEvents-serialization
Browse files Browse the repository at this point in the history
Fix `combineEvents` serialization
  • Loading branch information
sergeysova authored Aug 25, 2022
2 parents a9e011d + 57ea9cc commit 830aa1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/combine-events/combine-events.fork.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDomain, fork, allSettled } from 'effector';
import { createDomain, fork, allSettled, serialize, createEvent } from 'effector';

import { combineEvents } from './index';

Expand Down Expand Up @@ -100,3 +100,16 @@ test('do not affects another scope', async () => {
}
`);
});

test('do not interfere its internal state to serialized scope', async () => {
const one = createEvent();
const two = createEvent();
const scope = fork();

combineEvents({ events: { one, two } });

await allSettled(one, { scope });
await allSettled(two, { scope });

expect(serialize(scope, { onlyChanges: true })).toEqual({});
});
6 changes: 3 additions & 3 deletions src/combine-events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export function combineEvents<P>({
const keys = Object.keys(events);
const defaultShape = Array.isArray(events) ? [...keys].fill('') : {};

const $counter = createStore(keys.length);
const $results = createStore(defaultShape);
const $counter = createStore(keys.length, { serialize: 'ignore' });
const $results = createStore(defaultShape, { serialize: 'ignore' });

$counter.reset(sample(target));
$results.reset(target);
Expand All @@ -71,7 +71,7 @@ export function combineEvents<P>({
}

for (const key of keys) {
const $isDone = createStore(false)
const $isDone = createStore(false, { serialize: 'ignore' })
.on(events[key], () => true)
.reset(target);

Expand Down

0 comments on commit 830aa1e

Please sign in to comment.