Skip to content
Myr

All tests pass!

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by Michel Weststrate · parent f8d4056 · Browse files · 3 files+22 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+22 added−8 removed

  • tests:+13 added−0 removed
  • other:+9 added−8 removed

3 files+22 added−8 removed

added:__tests__/empty.ts+13 added
modified:src/patches.ts+6 added-6 removed
110 unmodified lines
111) {112 let {base, copy} = state113114 let i = 0115 for (const value of base) {115 base.forEach(value => {116 if (!copy.has(value)) {117 const path = basePath.concat([i])118 patches.push({119 op: "remove",
6 unmodified lines
126 value127 })128 }129 i++130 }130 })131 i = 0132 for (const value of copy) {132 copy.forEach(value => {133 if (!base.has(value)) {134 const path = basePath.concat([i])135 patches.push({136 op: "add",
6 unmodified lines
143 value144 })145 }146 i++147 }147 })148}149150export function applyPatches<T>(draft: T, patches: Patch[]): T {151 for (const patch of patches) {151 patches.forEach(patch => {152 const {path, op} = patch153154 if (!path.length) throw new Error("Illegal state")155
44 unmodified lines
200 break201 default:202 throw new Error("Unsupported patch operation: " + op)203 }204 }204 })205206 return draft207}
modified:src/proxy.ts+3 added-2 removed
262 unmodified lines
263 },264 clear: state => () => {265 markChanged(state)266 state.assigned = new Map()267 for (const key of latest(state).keys()) {267 each(latest(state).keys(), (_, key) => {268 // @ts-ignore269 state.assigned.set(key, false)269 }270 })271 return state.copy!.clear()272 },273 // @ts-ignore274 forEach: (state, _, receiver) => (cb, thisArg) =>
156 unmodified lines