Skip to content

Commit

Permalink
Merge pull request #903 from kireevmp/fix/ignored-stores-serialized-w…
Browse files Browse the repository at this point in the history
…ith-forked-value

Fix ignored stores serializing forked initial value
  • Loading branch information
zerobias committed Jul 19, 2023
2 parents 4fd2e90 + 466335c commit 476e907
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/effector/__tests__/fork/serialize.test.ts
Expand Up @@ -98,6 +98,16 @@ test('serialize: ignore with fork(values)', async () => {
expect(serialize(scope)).toEqual({b: 1})
})

test('serialize: ignore with fork(values) for unchanged stores', async () => {
const $a = createStore(0, {sid: 'a', serialize: 'ignore'})

const scope = fork({
values: [[$a, 1]],
})

expect(serialize(scope)).toStrictEqual({})
})

describe('serialize: custom', () => {
test('base case', async () => {
expect.assertions(4)
Expand Down
7 changes: 7 additions & 0 deletions src/effector/fork/fork.ts
Expand Up @@ -4,6 +4,7 @@ import type {Domain, ValuesMap, HandlersMap, Scope, Store} from '../unit.h'
import {normalizeValues} from './util'
import {createScope} from './createScope'
import {forEach} from '../collection'
import {getMeta} from '../getter'

type ForkConfig = {
values?: ValuesMap
Expand Down Expand Up @@ -39,6 +40,12 @@ export function fork(
Object.assign(scope.values.sidMap, sidMap)
forEach(unitMap, (value, unit) => {
scope.values.idMap[(unit as Store<any>).stateRef.id] = value

const serialize = getMeta(unit, 'serialize')
const sid = getMeta(unit, 'sid')
if (serialize === 'ignore') {
scope.sidSerializeSettings.set(sid, {ignore: true})
}
})
scope.fromSerialize =
!Array.isArray(config.values) && !(config.values instanceof Map)
Expand Down

0 comments on commit 476e907

Please sign in to comment.