fix map patches
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Andrey Boldyrev · committed by Andrey Boldyrev · parent 77051a9 · Browse files · 1 file·+23 added−21 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+23 added−21 removed
- other:+23 added−21 removed
Provenance
- Commit
0de782c- Tree
1b4a29a- Author
Andrey Boldyrev <runnez@yandex.ru>- Committer
Andrey Boldyrev <runnez@yandex.ru>- Parent
77051a9
1 file changed+23 added−21 removed
modified:src/es5.js+23 added-21 removed
52 unmodified lines53 scope,54 modified: false,55 finalizing: false, // es5 only56 finalized: false,57- assigned: {},57+ assigned: isMap(base) ? new Map() : {},58 parent,59 base,60 draft,61 drafts: isSet(base) ? new Map() : null,108 unmodified lines170 }171 172 const mapTraps = finalizeTraps({173 size: state => latest(state).size,174- get: state => key => {175- const value = latest(state).get(key)176-177- if (state.finalizing || state.finalized || !isDraftable(value)) {178- return value179- }180-181- if (value !== state.base.get(key)) {182- return value183- }184- const draft = createProxy(value, state)185- prepareCopy(state)186- state.copy.set(key, draft)187- return draft188- },174+ has: state => key => latest(state).has(key),175 set: state => (key, value) => {176 if (latest(state).get(key) !== value) {177 prepareCopy(state)178 markChanged(state)179+ state.assigned.set(key, true)180 state.copy.set(key, value)181 }182 return state.draft183 },184 delete: state => key => {185 prepareCopy(state)186 markChanged(state)187+ state.assigned.set(key, false)188 state.copy.delete(key)189 return false190 },191 clear: state => () => {192 if (!state.copy) {193 prepareCopy(state)194 }195 markChanged(state)196+ state.assigned = new Map()197+ for (const key of latest(state).keys()) {198+ state.assigned.set(key, false)199+ }200 return state.copy.clear()201 },210- has: state => key => {211- return latest(state).has(key)212- },202 forEach: (state, key, reciever) => cb => {203 latest(state).forEach((value, key, map) => {204 cb(reciever.get(key), key, map)205 })206 },218- keys: state => () => {219- return latest(state).keys()207+ get: state => key => {208+ const value = latest(state).get(key)209+210+ if (state.finalizing || state.finalized || !isDraftable(value)) {211+ return value212+ }213+214+ if (value !== state.base.get(key)) {215+ return value216+ }217+ const draft = createProxy(value, state)218+ prepareCopy(state)219+ state.copy.set(key, draft)220+ return draft221 },222+ keys: state => () => latest(state).keys(),223 values: iterateMapValues,224 entries: iterateMapValues225 })226 243 unmodified lines