(
partialSnapshot: any,
onInvalidated?: OnReferenceInvalidated<Instance<typeof Todo>>,
customRef = false
)
| 23 | }) |
| 24 | |
| 25 | const createStore = ( |
| 26 | partialSnapshot: any, |
| 27 | onInvalidated?: OnReferenceInvalidated<Instance<typeof Todo>>, |
| 28 | customRef = false |
| 29 | ) => { |
| 30 | const refOptions = { |
| 31 | onInvalidated, |
| 32 | get(identifier: ReferenceIdentifier, parent: IAnyStateTreeNode | null) { |
| 33 | return (parent as Instance<typeof Store>).todos.find(t => t.id === identifier) |
| 34 | }, |
| 35 | set(value: Instance<typeof Todo>): ReferenceIdentifier { |
| 36 | return value.id |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (!customRef) { |
| 41 | // @ts-ignore |
| 42 | delete refOptions.get |
| 43 | // @ts-ignore |
| 44 | delete refOptions.set |
| 45 | } |
| 46 | |
| 47 | const Store = types.model({ |
| 48 | todos: types.array(Todo), |
| 49 | onInv: types.maybe(types.reference(Todo, refOptions as any)), |
| 50 | single: types.safeReference(Todo), |
| 51 | deep: types.optional( |
| 52 | types.model({ |
| 53 | single: types.safeReference(Todo) |
| 54 | }), |
| 55 | {} |
| 56 | ), |
| 57 | arr: types.array(types.safeReference(Todo)), |
| 58 | map: types.map(types.safeReference(Todo)) |
| 59 | }) |
| 60 | |
| 61 | const s = Store.create(createSnapshot(partialSnapshot)) |
| 62 | unprotect(s) |
| 63 | return s |
| 64 | } |
| 65 | |
| 66 | for (const customRef of [false, true]) { |
| 67 | describe(`onInvalidated - customRef: ${customRef}`, () => { |
no test coverage detected
searching dependent graphs…