Skip to content
Myr

currying WIP

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 89e0d24 · Browse files · 1 file+17 added−3 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+17 added−3 removed

  • other:+17 added−3 removed

1 file+17 added−3 removed

modified:immer.js+17 added-3 removed
80 unmodified lines
81 * @param {Function} thunk - function that receives a proxy of the base state as first argument and which can be freely modified82 * @returns {any} a new state, or the base state if nothing was modified83 */84function immer(baseState, thunk) {85 // curried invocation86 if (arguments.length === 1) {87 // TODO: check arg is fn88 return function() {89 // TODO: check arg1 is object / array90 const args = arguments91 return immer(args[0], draft => {92 args[0] = draft // blegh!93 baseState.apply(null, args)94 })95 }96 }9798 // TODO: check args99 const revocableProxies = []100101 class State {102 constructor(parent, base) {
56 unmodified lines
159160 markChanged() {161 if (!this.modified) {162 this.modified = true149 this.copy = Array.isArray(this.base) // TODO: eliminate those isArray checks?163 this.copy = Array.isArray(this.base)164 ? this.base.slice()151 : Object.assign({}, this.base)165 : Object.assign({}, this.base) // TODO: eliminate those isArray checks?166 Object.assign(this.copy, this.proxies) // yup that works for arrays as well167 if (this.parent) this.parent.markChanged()168 }169 }
76 unmodified lines
246 if(autoFreeze) {247 Object.freeze(value)248 }249 * */236 autoFreeze && Object.freeze(value);250 autoFreeze && Object.freeze(value)251 return value252}253254/**
16 unmodified lines