{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-theresa/src/client/reactive/active-expression-rewriting/active-expression-rewriting.js"],"names":["BaseActiveExpression","frameBasedAExpr","Stack","CompositeKey","InjectiveMap","BidirectionalMultiMap","using","isFunction","expressionAnalysisMode","window","__expressionAnalysisMode__","analysisModeManager","__enter__","__exit__","top","ExpressionAnalysis","recalculateDependencies","aexpr","disconnectAllFor","check","value","isError","withElement","result","evaluateToCurrentValue","Dependency","getOrCreateFor","context","identifier","type","key","for","getOrCreateRightFor","constructor","_type","isTracked","updateTracking","hasAExprsForDep","untrack","track","contextIdentifierValue","isGlobal","isGlobalDependency","associate","dataStructure","Array","Set","Map","dataHook","getOrCreate","forStructure","wrappingHook","getOrCreateForProperty","HTMLElement","tagName","mutationObserverHook","getOrCreateForElement","eventBasedHook","instance","disconnectAllForDependency","compKey","getLeftFor","keysFor","undefined","notifyAExprs","aexprs","getAExprsForDep","checkAndNotifyAExprs","isMemberDependency","isLocalDependency","object","self","getAsDependencyDescription","property","name","scope","Error","DependenciesToAExprs","_depsToAExprs","dep","disconnectAllForAExpr","deps","getDepsForAExpr","removeAllLeftFor","forEach","from","getRightsFor","getLeftsFor","length","hasDepsForAExpr","clear","getAllLeft","HooksToDependencies","_hooksToDeps","hook","remove","getDepsForHook","getHooksForDep","hasDepsForHook","hasHooksForDep","ContextAndIdentifierCompositeKey","CompositeKeyToDependencies","CompositeKeyToSourceCodeHook","DataStructureHookByDataStructure","WeakMap","PropertyWrappingHookByProperty","MutationObserverHookByHTMLElement","EventBasedHookByHTMLElement","Hook","installed","notifyDependencies","SourceCodeHook","install","uninstall","DataStructureHook","getPrototypeDescriptors","obj","proto","prototype","descriptors","Object","getOwnPropertyDescriptors","entries","map","desc","wrapProperty","descriptor","after","defineProperty","assign","args","apply","call","monitorProperties","prototypeDescriptors","filter","addDescriptor","__compareAExprResults__","console","warn","PropertyWrappingHook","configurable","enumerable","getOwnPropertyDescriptor","get","set","MutationObserverHook","element","_element","o","MutationObserver","mutations","observer","changeHappened","observe","attributes","attributeFilter","attributeOldValue","characterData","characterDataOldValue","childList","subtree","EventBasedHook","addEventListener","editor","on","FrameBasedHook","_instance","x","ae","onChange","aexprStack","RewritingActiveExpression","func","meta","strategy","new","target","addToRegistry","dispose","asAExpr","supportsDependencies","dependencies","DependencyAPI","sharedDependenciesWith","otherAExpr","ownDependencies","all","otherDependencies","own","shared","other","computeDiff","_aexpr","getDependencies","locals","dependency","members","globals","globalRef","global","DependencyManager","currentAExpr","checkAndNotify","associateMember","prop","associateGlobal","globalName","associateLocal","varName","TracingHandler","memberUpdated","globalUpdated","localUpdated","reset","traceMember","getMember","getAndCallMember","setMember","val","setMemberAddition","setMemberSubtraction","setMemberMultiplication","setMemberDivision","setMemberRemainder","setMemberExponentiation","setMemberLeftShift","setMemberRightShift","setMemberUnsignedRightShift","setMemberBitwiseAND","setMemberBitwiseXOR","setMemberBitwiseOR","deleteMember","getLocal","setLocal","getGlobal","setGlobal"],"mappings":";;;;;;AAMSA,0B,qBAAAA,oB;;AACGC,qB;;AAELC,W;;AACAC,kB;;AACAC,kB;;AACAC,2B;;AAkBEC,W,UAAAA,K;AAAOC,gB,UAAAA,U;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAChB;AACA;AACA,UAAIC,yBAAyB,KAA7B;;AACAC,aAAOC,0BAAP,GAAoC,KAApC;;AAEA,YAAMC,sBAAsB;AAC1BC,oBAAY;AACV,8HAAyB,IAAzB;AACAH,iBAAOC,0BAAP,8FAAoCF,sBAApC;AACD,SAJyB;AAK1BK,mBAAW;AACT,8HAAyB,CAAC,CAAC,sGAAWC,GAAX,EAA3B;AACAL,iBAAOC,0BAAP,8FAAoCF,sBAApC;AACD;AARyB,OAA5B;;AAUA,YAAMO,kBAAN,CAAyB;;AAEvB,eAAOC,uBAAP,CAA+BC,KAA/B,EAAsC;AACpC;AACA,uHAAkBC,gBAAlB,CAAmCD,KAAnC;AACA,eAAKE,KAAL,CAAWF,KAAX;AACD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GAAvC,EAA4C;AACjD,cAAMpM,SAAS6F,IAAIyF,IAAJ,KAAac,GAA5B;AACA,kHAAeR,aAAf,CAA6B/F,GAA7B,EAAkCyF,IAAlC;AACA,eAAOtL,MAAP;AACD;;;;AAEM,eAASiN,YAAT,CAAsBpH,GAAtB,EAA2ByF,IAA3B,EAAiC;AACtC,cAAMtL,SAAS,OAAO6F,IAAIyF,IAAJ,CAAtB;AACA,kHAAeM,aAAf,CAA6B/F,GAA7B,EAAkCyF,IAAlC;AACA,eAAOtL,MAAP;AACD;;;;AAEM,eAASkN,QAAT,CAAkB9J,KAAlB,EAAyBsI,OAAzB,EAAkC7L,KAAlC,EAAyC;AAC9C,uGAAIZ,sBAAJ,EAA4B;AAC1BmE,gBAAMsI,OAAN,IAAiB7L,KAAjB;AACA,uHAAkB4L,cAAlB,CAAiCrI,KAAjC,EAAwCsI,OAAxC;AACD;AACF;;;;AAEM,eAASyB,QAAT,CAAkB/J,KAAlB,EAAyBsI,OAAzB,EAAkC7L,KAAlC,EAAyC;AAC9CuD,cAAMsI,OAAN,IAAiB7L,KAAjB;AACA,kHAAeiM,YAAf,CAA4B1I,KAA5B,EAAmCsI,OAAnC;AACD;;;;AAEM,eAAS0B,SAAT,CAAmB5B,UAAnB,EAA+B;AACpC,uGAAIvM,sBAAJ,EAA4B;AAC1B,uHAAkBsM,eAAlB,CAAkCC,UAAlC;AACD;AACF;;;;AAEM,eAAS6B,SAAT,CAAmB7B,UAAnB,EAA+B;AACpC,kHAAeK,aAAf,CAA6BL,UAA7B;AACD;;;;oHAEc9L,K","file":"active-expression-rewriting.js","sourcesContent":["import 'lang';\n\n/*HTML \n<img src=\"https://lively-kernel.org/lively4/lively4-core/media/lively4_logo_smooth_100.png\"></img>'s Implementation of AExprs\nHTML*/\n\nimport { BaseActiveExpression } from 'active-expression';\nimport * as frameBasedAExpr from \"active-expression-frame-based\";\n\nimport Stack from 'src/client/reactive/utils/stack.js';\nimport CompositeKey from './composite-key.js';\nimport InjectiveMap from './injective-map.js';\nimport BidirectionalMultiMap from './bidirectional-multi-map.js';\n/*HTML \n<div style='border: 1px dashed orange'>\n<editor-widget-location-info></editor-widget-location-info>\n</div>\nHTML*/\n/*HTML\n<div style='border: 1px dashed orange'>\n<codemirror-playground></codemirror-playground>\n</div>\nHTML*/\n\n/*HTML\n<div style='border: 1px dashed orange'>\n<span style=\"color: red\">hello</span>\n</div>\nHTML*/\n\nimport { using, isFunction } from 'utils';\n/*HTML <div style=\"background-color: green\">hoo</div> HTML*/\n/*MD # Dependency Analysis MD*/\nlet expressionAnalysisMode = false;\nwindow.__expressionAnalysisMode__ = false;\n\nconst analysisModeManager = {\n  __enter__() {\n    expressionAnalysisMode = true;\n    window.__expressionAnalysisMode__ = expressionAnalysisMode;\n  },\n  __exit__() {\n    expressionAnalysisMode = !!aexprStack.top();\n    window.__expressionAnalysisMode__ = expressionAnalysisMode;\n  }\n}\nclass ExpressionAnalysis {\n  \n  static recalculateDependencies(aexpr) {\n    // #TODO: compute diff of Dependencies\n    DependencyManager.disconnectAllFor(aexpr);\n    this.check(aexpr);\n  }\n  \n  static check(aexpr) {\n    let value, isError;\n    using([analysisModeManager], () => {\n      // Do the function execution in ExpressionAnalysisMode\n      aexprStack.withElement(aexpr, () => {\n        const result = aexpr.evaluateToCurrentValue();\n        value = result.value\n        isError = result.isError\n      });\n    });\n  }\n\n}\n\nclass Dependency {\n  static getOrCreateFor(context, identifier, type) {\n    const key = ContextAndIdentifierCompositeKey.for(context, identifier);\n    return CompositeKeyToDependencies.getOrCreateRightFor(key, () => new Dependency(context, identifier, type));\n  }\n\n  // #TODO: compute and cache isGlobal\n  constructor(context, identifier, type) {\n    this._type = type;\n    \n    this.isTracked = false;\n  }\n\n  updateTracking() {\n    if (this.isTracked === DependenciesToAExprs.hasAExprsForDep(this)) { return; }\n    if (this.isTracked) {\n      this.untrack();\n    } else {\n      this.track();\n    }\n  }\n\n  track() {\n    this.isTracked = true;\n\n    const [context, identifier, value] = this.contextIdentifierValue();\n    const isGlobal = this.isGlobalDependency();\n\n    /*HTML <span style=\"font-weight: bold;\">Source Code Hook</span>: for anything <span style=\"color: green; font-weight: bold;\">members or locals</span> HTML*/\n    // always employ the source code hook\n    HooksToDependencies.associate(SourceCodeHook.getOrCreateFor(context, identifier), this);\n\n    /*HTML <span style=\"font-weight: bold;\">Data Structure Hook</span>: for <span style=\"color: green; font-weight: bold;\">Sets, Arrays, Maps</span> HTML*/\n    var dataStructure;\n    if (this._type === 'member') {\n      dataStructure = context;\n    } else if(this._type === 'local') {\n      dataStructure = value;\n    }\n    if (dataStructure instanceof Array || dataStructure instanceof Set || dataStructure instanceof Map) {\n      const dataHook = DataStructureHookByDataStructure.getOrCreate(dataStructure, dataStructure => DataStructureHook.forStructure(dataStructure));\n      HooksToDependencies.associate(dataHook, this);\n    }\n\n    /*HTML <span style=\"font-weight: bold;\">Wrapping Hook</span>: only for <span style=\"color: green; font-weight: bold;\">\"that\"</span> HTML*/\n    if (isGlobal && identifier === 'that') {\n      const wrappingHook = PropertyWrappingHook.getOrCreateForProperty(identifier);\n      HooksToDependencies.associate(wrappingHook, this);\n    }\n\n    /*HTML <span style=\"font-weight: bold;\">Mutation Observer Hook</span>: handling <span style=\"color: green; font-weight: bold;\">HTMLElements</span> HTML*/\n    if (this._type === 'member' && context instanceof HTMLElement) {\n      // #HACK #TODO: for now, ignore Knotview if unused for Mutations -> need to better separate those hooks, e.g. do not recursively check ALL attribute change, etc.\n      if (!(context.tagName === 'KNOT-VIEW' && (identifier === 'knot' || identifier === 'knotLabel'))) {\n        // TODO: the member also influences what kind of observer we want to use!\n        const mutationObserverHook = MutationObserverHook.getOrCreateForElement(context);\n        HooksToDependencies.associate(mutationObserverHook, this);\n      }\n    }\n\n    /*HTML <span style=\"font-weight: bold;\">Event-based Change Hook</span>: handling <span style=\"color: green; font-weight: bold;\">HTMLElements</span> HTML*/\n    if (this._type === 'member' && context instanceof HTMLElement) {\n      const eventBasedHook = EventBasedHook.getOrCreateForElement(context);\n      // #TODO: we have to acknowledge that different properties require different events to listen on\n      //  e.g. code-mirror might have 'value' (so need to listen for 'change') or 'getCursor' (so need to listen for 'cursorActivity')\n      // eventBasedHook.listenFor(identifier);\n      HooksToDependencies.associate(eventBasedHook, this);\n    }\n\n    /*HTML <span style=\"font-weight: bold;\">Frame-based Change Hook</span>: handling <span style=\"color: green; font-weight: bold;\">Date</span> HTML*/\n// -    if ((this._type === 'member' && context === Date && identifier === 'now') ||\n    if (isGlobal && identifier === 'Date') {\n      HooksToDependencies.associate(FrameBasedHook.instance, this);\n    }\n  }\n\n  untrack() {\n    this.isTracked = false;\n    HooksToDependencies.disconnectAllForDependency(this);\n  }\n\n  contextIdentifierValue() {\n    const compKey = CompositeKeyToDependencies.getLeftFor(this);\n    \n    const [context, identifier] = ContextAndIdentifierCompositeKey.keysFor(compKey);\n    const value = context !== undefined ? context[identifier] : undefined;\n    \n    return [context, identifier, value];\n  }\n\n  notifyAExprs() {\n    const aexprs = DependenciesToAExprs.getAExprsForDep(this);\n    DependencyManager.checkAndNotifyAExprs(aexprs);\n  }\n  \n  isMemberDependency() {\n    return this._type === 'member' && !this.isGlobal();\n  }\n  isGlobalDependency() {\n    return this._type === 'member' && this.isGlobal();\n  }\n  isLocalDependency() {\n    return this._type === 'local';\n  }\n  isGlobal() {\n    const compKey = CompositeKeyToDependencies.getLeftFor(this);\n    if (!compKey) {\n      return false;\n    }\n    const [object] = ContextAndIdentifierCompositeKey.keysFor(compKey);\n    return object === self;\n  }\n\n  getAsDependencyDescription() {\n    const [context, identifier, value] = this.contextIdentifierValue();\n    \n    if (this.isMemberDependency()) {\n      return {\n        object: context,\n        property: identifier,\n        value\n      };\n    } else if (this.isGlobalDependency()) {\n      return {\n        name: identifier,\n        value\n      };\n    } else if (this.isLocalDependency()) {\n      return {\n        scope: context,\n        name: identifier,\n        value\n      };\n    } else {\n      throw new Error('Dependency is neighter local, member, nor global.');\n    }\n  }\n\n}\n\nconst DependenciesToAExprs = {\n  _depsToAExprs: new BidirectionalMultiMap(),\n\n  associate(dep, aexpr) {\n    this._depsToAExprs.associate(dep, aexpr);\n    dep.updateTracking();\n  },\n\n  disconnectAllForAExpr(aexpr) {\n    const deps = this.getDepsForAExpr(aexpr);\n    this._depsToAExprs.removeAllLeftFor(aexpr);\n    deps.forEach(dep => dep.updateTracking());\n  },\n\n  getAExprsForDep(dep) {\n    return Array.from(this._depsToAExprs.getRightsFor(dep));\n  },\n  getDepsForAExpr(aexpr) {\n    return Array.from(this._depsToAExprs.getLeftsFor(aexpr));\n  },\n\n  hasAExprsForDep(dep) {\n    return this.getAExprsForDep(dep).length >= 1;\n  },\n  hasDepsForAExpr(aexpr) {\n    return this.getDepsForAExpr(aexpr).length >= 1;\n  },\n  \n  /*\n   * Removes all associations.\n   */\n  clear() {\n    this._depsToAExprs.clear();\n    this._depsToAExprs.getAllLeft()\n      .forEach(dep => dep.updateTracking());\n  }\n};\n\nconst HooksToDependencies = {\n  _hooksToDeps: new BidirectionalMultiMap(),\n  \n  associate(hook, dep) {\n    this._hooksToDeps.associate(hook, dep);\n  },\n  remove(hook, dep) {\n    this._hooksToDeps.remove(hook, dep);\n  },\n  \n  disconnectAllForDependency(dep) {\n    this._hooksToDeps.removeAllLeftFor(dep);\n  },\n  \n  getDepsForHook(hook) {\n    return Array.from(this._hooksToDeps.getRightsFor(hook));\n  },\n  getHooksForDep(dep) {\n    return Array.from(this._hooksToDeps.getLeftsFor(dep));\n  },\n  \n  hasDepsForHook(hook) {\n    return this.getDepsForHook(hook).length >= 1;\n  },\n  hasHooksForDep(dep) {\n    return this.getHooksForDep(dep).length >= 1;\n  },\n  \n  /*\n   * Removes all associations.\n   */\n  clear() {\n    this._hooksToDeps.clear();\n  }\n};\n\n// 1. (obj, prop) or (scope, name) -> ContextAndIdentifierCompositeKey\n// - given via ContextAndIdentifierCompositeKey\nconst ContextAndIdentifierCompositeKey = new CompositeKey();\n\n// 2.1. ContextAndIdentifierCompositeKey 1<->1 Dependency\n// - CompositeKeyToDependencies\nconst CompositeKeyToDependencies = new InjectiveMap();\n// 2.2. Dependency *<->* AExpr\n// - DependenciesToAExprs\n\n/** Source Code Hooks */\n// 3.1. ContextAndIdentifierCompositeKey 1<->1 SourceCodeHook\n// - CompositeKeyToSourceCodeHook\nconst CompositeKeyToSourceCodeHook = new InjectiveMap();\n// 3.2. SourceCodeHook *<->* Dependency\n// - HooksToDependencies\n\n/** Data Structure Hooks */\n// 4.1 DataStructureHookByDataStructure\nconst DataStructureHookByDataStructure = new WeakMap(); // WeakMap<(Set/Array/Map), DataStructureHook>\n/** Wrapping Hooks */\n// 4.2 PropertyWrappingHookByProperty\nconst PropertyWrappingHookByProperty = new Map(); // Map<(String/Symbol), PropertyWrappingHook>\n/** Mutation Observer Hooks */\n// 4.3 DataStructureHookByDataStructure\nconst MutationObserverHookByHTMLElement = new WeakMap(); // WeakMap<HTMLElement, MutationObserverHook>\n/** XXX */\n// 4.4 XXX\nconst EventBasedHookByHTMLElement = new WeakMap(); // WeakMap<HTMLElement, EventBasedHook>\n\n\nclass Hook {\n  constructor() {\n    this.installed = false;\n  }\n  \n  notifyDependencies() {\n    HooksToDependencies.getDepsForHook(this).forEach(dep => dep.notifyAExprs())\n  }\n}\n\nclass SourceCodeHook extends Hook {\n  static getOrCreateFor(context, identifier) {\n    const compKey = ContextAndIdentifierCompositeKey.for(context, identifier);\n    return CompositeKeyToSourceCodeHook.getOrCreateRightFor(compKey, key => new SourceCodeHook());\n  }\n  \n  constructor(context, identifier) {\n    super();\n\n    this.context = context;\n    this.identifier = identifier;\n  }\n  \n  install() {}\n  uninstall() {}\n}\n\nclass DataStructureHook extends Hook {\n  static forStructure(dataStructure) {\n    const hook = new DataStructureHook();\n    \n    function getPrototypeDescriptors(obj) {\n      const proto = obj.constructor.prototype;\n\n      const descriptors = Object.getOwnPropertyDescriptors(proto);\n      return Object.entries(descriptors).map(([key, desc]) => (desc.key = key, desc))\n    }\n\n    function wrapProperty(obj, descriptor, after) {\n      Object.defineProperty(obj, descriptor.key, Object.assign({}, descriptor, {\n        value(...args) {\n          try {\n            return descriptor.value.apply(this, args);\n          } finally {\n            after.call(this, ...args)\n          }\n        }\n      }));\n    }\n\n    function monitorProperties(obj) {\n      const prototypeDescriptors = getPrototypeDescriptors(obj);\n      Object.entries(Object.getOwnPropertyDescriptors(obj)); // unused -> need for array\n\n      prototypeDescriptors\n        .filter(descriptor => descriptor.key !== 'constructor') // the property constructor needs to be a constructor if called (as in cloneDeep in lodash); We leave it out explicitly as the constructor does not change any state #TODO\n        .forEach(addDescriptor => {\n          // var addDescriptor = prototypeDescriptors.find(d => d.key === 'add')\n          if (addDescriptor.value) {\n            if (isFunction(addDescriptor.value)) {\n              wrapProperty(obj, addDescriptor, function() {\n                // #HACK #TODO we need an `withoutLayer` equivalent here\n                if (window.__compareAExprResults__) { return; }\n\n                this; // references the modified container\n                hook.notifyDependencies();\n              });\n            } else {\n              console.warn(`Property ${addDescriptor.key} has a value that is not a function, but ${addDescriptor.value}.`)\n            }\n          } else {\n            console.warn(`Property ${addDescriptor.key} has no value.`)\n          }\n        });\n    }\n\n    monitorProperties(dataStructure);\n    \n    // set.add = function add(...args) {\n    //   const result = Set.prototype.add.call(this, ...args);\n    //   hook.notifyDependencies();\n    //   return result;\n    // }\n    return hook;\n  }\n}\n\nclass PropertyWrappingHook extends Hook {\n  static getOrCreateForProperty(property) {\n    return PropertyWrappingHookByProperty.getOrCreate(property, () => new PropertyWrappingHook(property));\n  }\n  \n  constructor(property) {\n    super();\n\n    this.value = self[property];\n    const { configurable, enumerable } = Object.getOwnPropertyDescriptor(self, property);\n\n    // #TODO: keep old property accessors if present (otherwise, we do not interact with COP and ourselves, i.e. other property wrappers)\n    Object.defineProperty(self, property, {\n      configurable,\n      enumerable,\n      \n      get: () => this.value,\n      set: value => {\n        const result = this.value = value;\n        this.notifyDependencies();\n        return result;\n      }\n    });\n  }\n}\n\nclass MutationObserverHook extends Hook {\n  static getOrCreateForElement(element) {\n    return MutationObserverHookByHTMLElement.getOrCreate(element, () => new MutationObserverHook(element));\n  }\n  \n  constructor(element) {\n    super();\n\n    this._element = element;\n    \n    const o = new MutationObserver((mutations, observer) => {\n      // const mutationRecords = o.takeRecords();\n      // lively.notify(`mutation on ${this._element.tagName}; ${mutations\n      //               .filter(m => m.type === \"attributes\")\n      //               .map(m => m.attributeName).join(', ')}.`)\n      this.changeHappened();\n      // mutations.forEach(mutation => {\n      //   if(mutation.type == \"attributes\") {\n      //     lively.notify(\n      //       `${mutation.oldValue} -> ${mutation.target.getAttribute(mutation.attributeName)}`,\n      //       `attribute: ${mutation.attributeName}`\n      //     );\n      //   }\n      //   if(mutation.type == \"characterData\") {\n      //     lively.notify(\n      //       `${mutation.oldValue}}`,\n      //       `characterData`\n      //     );\n      //   }\n      //   if(mutation.type == \"childList\") {\n      //     lively.success(\n      //       `${mutation.addedNodes.length} added, ${mutation.removedNodes.length} removed`,\n      //       `childList`\n      //     );\n      //   }\n      // });\n    });\n\n    o.observe(this._element, {\n      attributes: true,\n      attributeFilter: undefined,\n      attributeOldValue: true,\n\n      characterData: true,\n      characterDataOldValue: true,\n\n      childList: true,\n\n      subtree: true,\n    });\n    \n    // o.disconnect();\n  }\n\n  changeHappened() {\n    this.notifyDependencies();\n  }\n}\n\nclass EventBasedHook extends Hook {\n  static getOrCreateForElement(element) {\n    return EventBasedHookByHTMLElement.getOrCreate(element, () => new EventBasedHook(element));\n  }\n  \n  constructor(element) {\n    super();\n\n    this._element = element;\n\n    // #TODO: when the type of an input element changes, 'value' or 'checked' become unavailable\n    if (this._element.tagName === 'INPUT') {\n      this._element.addEventListener('input', () => {\n        this.changeHappened();\n      });\n    } else if (this._element.tagName === 'LIVELY-CODE-MIRROR') {\n      this._element.editor.on('changes', () => {\n        this.changeHappened();\n      });\n    }\n  }\n  \n  changeHappened() {\n    this.notifyDependencies();\n  }\n}\n\nclass FrameBasedHook extends Hook {\n  static get instance() {\n    return this._instance = this._instance || new FrameBasedHook();\n  }\n  \n  constructor() {\n    super();\n    \n    let x = 0;\n    // #TODO: caution, we currently use a side-effect function! How can we mitigate this? E.g. using `Date.now()` as expression\n    let ae = frameBasedAExpr.aexpr(() => x++)\n    ae.onChange(() => {\n      this.changeHappened();\n    })\n\n  }\n  \n  changeHappened() {\n    this.notifyDependencies();\n  }\n}\n\n\nconst aexprStack = new Stack();\n\nexport class RewritingActiveExpression extends BaseActiveExpression {\n  constructor(func, ...args) {\n    super(func, ...args);\n    this.meta({ strategy: 'Rewriting' });\n    ExpressionAnalysis.recalculateDependencies(this);\n\n    if (new.target === RewritingActiveExpression) {\n      this.addToRegistry();\n    }\n  }\n\n  dispose() {\n    super.dispose();\n    DependencyManager.disconnectAllFor(this);\n  }\n  \n  asAExpr() {\n    return this;\n  }\n\n  supportsDependencies() {\n    return true;\n  }\n\n  dependencies() {\n    return new DependencyAPI(this);\n  }\n  \n  sharedDependenciesWith(otherAExpr) {\n    const ownDependencies = this.dependencies().all();\n    const otherDependencies = otherAExpr.dependencies().all();\n    const [own, shared, other] = ownDependencies.computeDiff(otherDependencies);\n    return shared;\n  }\n}\n\nclass DependencyAPI {\n  constructor(aexpr) {\n    this._aexpr = aexpr;\n  }\n  \n  getDependencies() {\n    return DependenciesToAExprs.getDepsForAExpr(this._aexpr);\n  }\n\n  all() {\n    return Array.from(this.getDependencies());\n  }\n  \n  locals() {\n    return this.getDependencies()\n      .filter(dependency => dependency.isLocalDependency())\n      .map(dependency => dependency.getAsDependencyDescription());\n  }\n\n  members() {\n    return this.getDependencies()\n      .filter(dependency => dependency.isMemberDependency())\n      .map(dependency => dependency.getAsDependencyDescription());\n  }\n\n  globals() {\n    return this.getDependencies()\n      .filter(dependency => dependency.isGlobalDependency())\n      .map(dependency => dependency.getAsDependencyDescription());\n  }\n}\n\nexport function aexpr(func, ...args) {\n  return new RewritingActiveExpression(func, ...args);\n}\n\nconst globalRef = typeof window !== \"undefined\" ? window : // browser tab\n  (typeof self !== \"undefined\" ? self : // web worker\n    global); // node.js\n\nclass DependencyManager {\n  static get currentAExpr() {\n    return aexprStack.top();\n  }\n  \n  // #TODO, #REFACTOR: extract into own method; remove from this class\n  static disconnectAllFor(aexpr) {\n    DependenciesToAExprs.disconnectAllForAExpr(aexpr);\n  }\n\n  // #TODO, #REFACTOR: extract into configurable dispatcher class\n  static checkAndNotifyAExprs(aexprs) {\n    aexprs.forEach(aexpr => {\n      ExpressionAnalysis.recalculateDependencies(aexpr);\n    });\n    aexprs.forEach(aexpr => aexpr.checkAndNotify());\n  }\n\n  /**\n   * **************************************************************\n   * ********************** associate *****************************\n   * **************************************************************\n   */\n  static associateMember(obj, prop) {\n    const dependency = Dependency.getOrCreateFor(obj, prop, 'member');\n    DependenciesToAExprs.associate(dependency, this.currentAExpr);\n  }\n\n  static associateGlobal(globalName) {\n    const dependency = Dependency.getOrCreateFor(globalRef, globalName, 'member');\n    DependenciesToAExprs.associate(dependency, this.currentAExpr);\n  }\n\n  static associateLocal(scope, varName) {\n    const dependency = Dependency.getOrCreateFor(scope, varName, 'local');\n    DependenciesToAExprs.associate(dependency, this.currentAExpr);\n  }\n\n}\n\nclass TracingHandler {\n\n  /**\n   * **************************************************************\n   * ********************** update ********************************\n   * **************************************************************\n   */\n  static memberUpdated(obj, prop) {\n    SourceCodeHook.getOrCreateFor(obj, prop).notifyDependencies();\n  }\n\n  static globalUpdated(globalName) {\n    SourceCodeHook.getOrCreateFor(globalRef, globalName).notifyDependencies();\n  }\n\n  static localUpdated(scope, varName) {\n    SourceCodeHook.getOrCreateFor(scope, varName).notifyDependencies();\n  }\n\n}\n\n/*\n * Disconnects all associations between active expressions and object properties\n * As a result no currently enable active expression will be notified again,\n * effectively removing them from the system.\n *\n * #TODO: Caution, this might break with some semantics, if we still have references to an aexpr!\n */\nexport function reset() {\n  ContextAndIdentifierCompositeKey.clear();\n\n  CompositeKeyToDependencies.clear();\n  DependenciesToAExprs.clear();\n\n  CompositeKeyToSourceCodeHook.clear();\n  HooksToDependencies.clear();\n}\n\n/*MD # Source Code Point Cuts MD*/\n/**\n * (C)RUD for member attributes\n */\nexport function traceMember(obj, prop) {\n  if (expressionAnalysisMode) {\n    DependencyManager.associateMember(obj, prop);\n  }\n}\n\nexport function getMember(obj, prop) {\n  if (expressionAnalysisMode) {\n    DependencyManager.associateMember(obj, prop);\n  }\n  const result = obj[prop];\n  return result;\n}\n\nexport function getAndCallMember(obj, prop, args = []) {\n  if (expressionAnalysisMode) {\n    DependencyManager.associateMember(obj, prop);\n  }\n  const result = obj[prop](...args);\n  return result;\n}\n\nexport function setMember(obj, prop, val) {\n  const result = obj[prop] = val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberAddition(obj, prop, val) {\n  const result = obj[prop] += val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberSubtraction(obj, prop, val) {\n  const result = obj[prop] -= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberMultiplication(obj, prop, val) {\n  const result = obj[prop] *= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberDivision(obj, prop, val) {\n  const result = obj[prop] /= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberRemainder(obj, prop, val) {\n  const result = obj[prop] %= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberExponentiation(obj, prop, val) {\n  const result = obj[prop] **= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberLeftShift(obj, prop, val) {\n  const result = obj[prop] <<= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberRightShift(obj, prop, val) {\n  const result = obj[prop] >>= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberUnsignedRightShift(obj, prop, val) {\n  const result = obj[prop] >>>= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberBitwiseAND(obj, prop, val) {\n  const result = obj[prop] &= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberBitwiseXOR(obj, prop, val) {\n  const result = obj[prop] ^= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function setMemberBitwiseOR(obj, prop, val) {\n  const result = obj[prop] |= val;\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function deleteMember(obj, prop) {\n  const result = delete obj[prop];\n  TracingHandler.memberUpdated(obj, prop);\n  return result;\n}\n\nexport function getLocal(scope, varName, value) {\n  if (expressionAnalysisMode) {\n    scope[varName] = value;\n    DependencyManager.associateLocal(scope, varName);\n  }\n}\n\nexport function setLocal(scope, varName, value) {\n  scope[varName] = value;\n  TracingHandler.localUpdated(scope, varName);\n}\n\nexport function getGlobal(globalName) {\n  if (expressionAnalysisMode) {\n    DependencyManager.associateGlobal(globalName);\n  }\n}\n\nexport function setGlobal(globalName) {\n  TracingHandler.globalUpdated(globalName);\n}\n\nexport default aexpr;\n"]}