some build fixes
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 7f5e301 · Browse files · 4 files·+10 added−102 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+10 added−102 removed
- tests:+1 added−1 removed
- other:+9 added−101 removed
Provenance
- Commit
65a377f- Tree
fa859a3- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
7f5e301
4 files changed+10 added−102 removed
modified:__tests__/patch.js+1 added-1 removed
616 unmodified lines617 []618 )619 })620 621-describe.only("sets - mutate - 1", () => {621+describe("sets - mutate - 1", () => {622 const findById = (set, id) => {623 for (const item of set) {624 if (item.id === id) return item625 }238 unmodified linesmodified:src/es5.ts-1 removed
9 unmodified lines10 isSet,11 hasSymbol,12 shallowCopy,13 DRAFT_STATE,14- iterateMapValues,14 makeIterable,15 latest16 } from "./common"17 import {proxyMap, hasMapChanges} from "./map"338 unmodified linesmodified:src/proxy.ts+7 added-99 removed
13 unmodified lines14 DRAFT_STATE,15 assignMap,16 assignSet,17 original,18- iterateMapValues,18 latest19 } from "./common"20 import {ImmerScope} from "./scope"22-import { proxyMap } from "./map"23-import { proxySet } from "./set"21+import {proxyMap} from "./map"22+import {proxySet} from "./set"23 24 // Do nothing before being finalized.25 export function willFinalize() {}26 39 unmodified lines66 67 // TODO: dedupe this, it is the same for ES568 if (isMap(base)) {69 const draft = proxyMap(base, parent) as any // TODO: typefix71- scope.drafts.push(draft);72- return draft;70+ scope.drafts.push(draft)71+ return draft72 }73 if (isSet(base)) {74 const draft = proxySet(base, parent) as any // TODO: typefix76- scope.drafts.push(draft);77- return draft;75+ scope.drafts.push(draft)76+ return draft77 }78 79 const state: ES6State<T> = {80 // Track which produce call this is associated with.166 unmodified lines247 /**248 * Map drafts249 */250 252-const mapTraps = makeTrapsForGetters<Map<any, any>>({253- [DRAFT_STATE]: state => state,254- size: state => latest(state).size,255- has: state => key => latest(state).has(key),256- set: state => (key, value) => {257- const values = latest(state)258- if (!values.has(key) || values.get(key) !== value) {259- markChanged(state)260- // @ts-ignore261- state.assigned.set(key, true)262- state.copy!.set(key, value)263- }264- return state.draft265- },266- delete: state => key => {267- if (latest(state).has(key)) {268- markChanged(state)269- // @ts-ignore270- state.assigned.set(key, false)271- return state.copy!.delete(key)272- }273- return false274- },275- clear: state => () => {276- markChanged(state)277- state.assigned = new Map()278- each(latest(state).keys(), (_, key) => {279- // @ts-ignore280- state.assigned.set(key, false)281- })282- return state.copy!.clear()283- },284- // @ts-ignore285- forEach: (state, _, receiver) => (cb, thisArg) =>286- latest(state).forEach((_, key, map) => {287- const value = receiver.get(key)288- cb.call(thisArg, value, key, map)289- }),290- get: state => key => {291- const drafts = state.modified ? state.copy : state.drafts292-293- // @ts-ignore TODO: ...or fix by using different ES6Draft types (but better just unify to maps)294- if (drafts!.has(key)) {295- // @ts-ignore296- const value = drafts.get(key)297-298- if (isDraft(value) || !isDraftable(value)) return value299-300- const draft = createProxy(value, state)301- // @ts-ignore302- drafts.set(key, draft)303- return draft304- }305-306- const value = latest(state).get(key)307- if (state.finalized || !isDraftable(value)) {308- return value309- }310-311- const draft = createProxy(value, state)312- //@ts-ignore313- drafts.set(key, draft)314- return draft315- },316- keys: state => () => latest(state).keys(),317- //@ts-ignore318- values: iterateMapValues,319- //@ts-ignore320- entries: iterateMapValues,321- [hasSymbol ? Symbol.iterator : "@@iterator"]: iterateMapValues322-})323-251 // Access a property without creating an Immer draft.252 function peek(draft, prop) {253 const state = draft[DRAFT_STATE]254 const desc = Reflect.getOwnPropertyDescriptor(9 unmodified lines264 state.modified = true265 const {base, drafts, parent} = state266 if (!isMap(base) && !isSet(base)) {267 // TODO: drop creating copies here?341- const copy = state.copy = shallowCopy(base)268+ const copy = (state.copy = shallowCopy(base))269 assign(copy, drafts)270 state.drafts = null271 }272 22 unmodified lines295 },296 {} as any297 )298 }372-373-function makeTrapsForGetters<T extends object>(374- getters: {375- [K in keyof T]: (376- state: ES6State<T>377- ) => /* Skip first arg of: ProxyHandler<T>[K] */ any378- }379-): ProxyHandler<T> {380- return assign({}, reflectTraps, {381- get(state, prop, receiver) {382- return getters.hasOwnProperty(prop)383- ? getters[prop](state, prop, receiver)384- : Reflect.get(state, prop, receiver)385- },386- setPrototypeOf(state) {387- throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft") // prettier-ignore388- }389- })390-}modified:tsconfig.json+2 added-1 removed
5 unmodified lines678910101112135 unmodified lines "target": "ES6", "strict": true, "declaration": true, "importHelpers": false, "noImplicitAny": false // TODO: true, "noImplicitAny": false, // TODO: true, "esModuleInterop": true }}