* Set the current value of a name, and optionally set it globally too. * Local set() sets the current value and (when appropriate) adds an undo * operation to the undo stack. Global set() may change the undo * operation at every level, so takes time linear in their number.
(name, value, global)
| 12988 | |
| 12989 | |
| 12990 | set(name, value, global) { |
| 12991 | if (global === void 0) { |
| 12992 | global = false; |
| 12993 | } |
| 12994 | |
| 12995 | if (global) { |
| 12996 | // Global set is equivalent to setting in all groups. Simulate this |
| 12997 | // by destroying any undos currently scheduled for this name, |
| 12998 | // and adding an undo with the *new* value (in case it later gets |
| 12999 | // locally reset within this environment). |
| 13000 | for (let i = 0; i < this.undefStack.length; i++) { |
| 13001 | delete this.undefStack[i][name]; |
| 13002 | } |
| 13003 | |
| 13004 | if (this.undefStack.length > 0) { |
| 13005 | this.undefStack[this.undefStack.length - 1][name] = value; |
| 13006 | } |
| 13007 | } else { |
| 13008 | // Undo this set at end of this group (possibly to `undefined`), |
| 13009 | // unless an undo is already in place, in which case that older |
| 13010 | // value is the correct one. |
| 13011 | const top = this.undefStack[this.undefStack.length - 1]; |
| 13012 | |
| 13013 | if (top && !top.hasOwnProperty(name)) { |
| 13014 | top[name] = this.current[name]; |
| 13015 | } |
| 13016 | } |
| 13017 | |
| 13018 | this.current[name] = value; |
| 13019 | } |
| 13020 | |
| 13021 | } |
| 13022 |
no outgoing calls
no test coverage detected