{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-mpm-debugging/src/client/reactive/active-expression-convention/active-expression-ticking.js"],"names":["BaseActiveExpression","TICKING_INSTANCES","Set","TickingActiveExpression","constructor","func","args","enable","new","target","addToRegistry","revoke","removeListeners","disable","enabled","delete","add","aexpr","check","iterable","forEach","checkAndNotify","clearDefaultActiveExpressions","clear"],"mappings":";;;;;;AAASA,gC,qBAAAA,oB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAET,kBAAMC,oBAAoB,IAAIC,GAAJ,EAA1B;;;;;;;;;;;;;;;AAEO,kBAAMC,uBAAN,SAAsCH,oBAAtC,CAA2D;;AAE9D;AACA;AACA;AACAI,4BAAYC,IAAZ,EAAkB,GAAGC,IAArB,EAA2B;AACvB,0BAAMD,IAAN,EAAY,GAAGC,IAAf;AACA,yBAAKC,MAAL;;AAEA,wBAAGC,IAAIC,MAAJ,KAAeN,uBAAlB,EAA2C;AACvC,6BAAKO,aAAL;AACH;AACJ;;AAED;AACAC,yBAAS;AACL,yBAAKC,eAAL;AACH;;AAEDC,0BAAU;AACN,yBAAKC,OAAL,GAAe,KAAf;AACAb,sCAAkBc,MAAlB,CAAyB,IAAzB;;AAEA,2BAAO,IAAP;AACH;;AAEDR,yBAAS;AACL,yBAAKO,OAAL,GAAe,IAAf;AACAb,sCAAkBe,GAAlB,CAAsB,IAAtB;;AAEA,2BAAO,IAAP;AACH;AA/B6D;;;;;;;;;;;;;;;;;;AAkC3D,qBAASC,KAAT,CAAeZ,IAAf,EAAqB,GAAGC,IAAxB,EAA8B;AAAE,uBAAO,IAAIH,uBAAJ,CAA4BE,IAA5B,EAAkC,GAAGC,IAArC,CAAP;AAAoD;;AAE3F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,qBAASY,KAAT,CAAeC,WAAWlB,iBAA1B,EAA6C;AAChDkB,yBAASC,OAAT,CAAiBH,SAASA,MAAMH,OAAN,IAAiBG,MAAMI,cAAN,EAA3C;AACH;;AAED;AACA;AACA;;;;AACO,qBAASC,6BAAT,GAAyC;AAC5CrB,kCAAkBsB,KAAlB;AACH","file":"active-expression-ticking.js","sourcesContent":["import { BaseActiveExpression } from 'active-expression';\n\nconst TICKING_INSTANCES = new Set();\n\nexport class TickingActiveExpression extends BaseActiveExpression {\n\n    // each implementation strategy ensures to track changes of the given expression\n    // in the case of ticking, we add the aexpr to a collection of tracked aexpr\n    // which enables them to recognize changes (here, explicitly through the `check` method)\n    constructor(func, ...args) {\n        super(func, ...args);\n        this.enable();\n\n        if(new.target === TickingActiveExpression) {\n            this.addToRegistry();\n        }\n    }\n\n    // TODO: refactor/extractMethod with InterpreterActiveExpression\n    revoke() {\n        this.removeListeners();\n    }\n\n    disable() {\n        this.enabled = false;\n        TICKING_INSTANCES.delete(this);\n\n        return this;\n    }\n\n    enable() {\n        this.enabled = true;\n        TICKING_INSTANCES.add(this);\n\n        return this;\n    }\n}\n\nexport function aexpr(func, ...args) { return new TickingActiveExpression(func, ...args); }\n\n// TODO: the concrete semantic of enabled and disabled aexprs are not clear yet.\n// Instead, they are related to this concrete implementation.\n// For example, what happens if a disabled aexpr is re-enabled AND the value of the aexpr\n// has already changed? SHould the callback be invoked with the  new value and the lastValue\n// before the disabling? or with the actual last value? Or should it not be invoked until\n// something changes? If so, what is the last value? Or should aexprs simply not be able to be\n// re-enabled again? Or should they not even be disable-able; then, it would be the duty of\n// the callback/a built-upon concept to implement thiese functionalities appropriately\nexport function check(iterable = TICKING_INSTANCES) {\n    iterable.forEach(aexpr => aexpr.enabled && aexpr.checkAndNotify());\n}\n\n// Remove all active expressions of this type from the system\n// afterward active expressions are only reachable by providing them explicitly in an iterable to `check`\n// Caution: Do not use this function unless you know what you are doing!\nexport function clearDefaultActiveExpressions() {\n    TICKING_INSTANCES.clear();\n}\n"]}