Skip to content
Myr

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 file

Take it

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

lines 1–4why, one step back
1import {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 back
5 constructor(parent) {
6 this.drafts = []7 this.parent = parent

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

line 8why, one step back
8

run prettier with master config before mergingMichel Weststratebefore adoptionae80361

lines 9–11why, one step back
9 // Whenever the modified draft contains a draft from another scope, we
10 // need to prevent auto-freezing so the unowned draft can be finalized.11 this.canAutoFreeze = true

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

line 12why, one step back
12

run prettier with master config before mergingMichel Weststratebefore adoptionae80361

lines 13–32why, one step back
13 // 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 back
33}
3435ImmerScope.current = null36ImmerScope.enter = function() {

run prettier with master config before mergingMichel Weststratebefore adoptionae80361

line 37why, one step back
37 return (this.current = new ImmerScope(this.current))

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

lines 38–40why, one step back
38}
3940function revoke(draft) {

run prettier with master config before mergingMichel Weststratebefore adoptionae80361

line 41why, one step back
41 draft[DRAFT_STATE].revoke()

Merge branch 'async-recipes'Michel Weststratebefore adoptionff210d8

line 42why, one step back
42}