scope.js
This file
Path
src/scope.js
42 lines · 940 bytes · JavaScript
Last changed by
run prettier with master config before mergingMichel Weststratebefore adoptionae80361
History of this fileTake it
Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
lines 1–4why, one step back1import {DRAFT_STATE} from "./common"23/** Each scope represents a `produce` call. */4export class ImmerScope {run prettier with master config before mergingMichel Weststratebefore adoptionae80361
lines 5–7why, one step back5 constructor(parent) {6 this.drafts = []7 this.parent = parentMerge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 8why, one step back8run prettier with master config before mergingMichel Weststratebefore adoptionae80361
lines 9–11why, one step back9 // Whenever the modified draft contains a draft from another scope, we10 // need to prevent auto-freezing so the unowned draft can be finalized.11 this.canAutoFreeze = trueMerge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 12why, one step back12run prettier with master config before mergingMichel Weststratebefore adoptionae80361
lines 13–32why, one step back13 // To avoid prototype lookups:14 this.patches = null15 }16 usePatches(patchListener) {17 if (patchListener) {18 this.patches = []19 this.inversePatches = []20 this.patchListener = patchListener21 }22 }23 revoke() {24 this.leave()25 this.drafts.forEach(revoke)26 this.drafts = null // Make draft-related methods throw.27 }28 leave() {29 if (this === ImmerScope.current) {30 ImmerScope.current = this.parent31 }32 }Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
lines 33–36why, one step back33}3435ImmerScope.current = null36ImmerScope.enter = function() {run prettier with master config before mergingMichel Weststratebefore adoptionae80361
line 37why, one step back37 return (this.current = new ImmerScope(this.current))Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
lines 38–40why, one step back38}3940function revoke(draft) {run prettier with master config before mergingMichel Weststratebefore adoptionae80361
line 41why, one step back41 draft[DRAFT_STATE].revoke()Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8
line 42why, one step back42}