{"version":3,"sources":["https://lively-kernel.org/lively4/swt1-debugging/src/client/reactive/active-expression-convention/active-expression-ticking.js"],"names":["BaseActiveExpression","clearDefaultActiveExpressions","check","aexpr","setExpressionOptionsForConventionStrategies","TICKING_INSTANCES","Set","func","options","rest","Object","assign","checkImmediately","TickingActiveExpression","constructor","args","add","new","target","addToRegistry","revoke","removeListeners","dispose","delete","disable2","disable","enable2","enable","setExpression","params","iterable","forEach","checkAndNotify","clear"],"mappings":";;;;;;AAASA,0B,qBAAAA,oB;;;;;;;;;;;mDA2EOC,8D;;;;;;;;;;;;;;2BAPAC,sC;;;;;;;;;;;;;;2BAVAC,sC;;;;;;;;;;;;;;iEAtDAC,4E;;;;;;;;;;;;;;AAJPJ,+D;;;;;;;;;AAET,YAAMK,oBAAoB,IAAIC,GAAJ,EAA1B;;;;;;;;AAAMD,4D;;;;;;;AAEC,eAASD,2CAAT,CAAqDG,IAArD,EAA2DC,UAAU,EAArE,EAAyE,GAAGC,IAA5E,EAAkF;AACvF,eAAO,CAACF,IAAD,EAAOG,OAAOC,MAAP,CAAc;AAC1BC,4BAAkB;AADQ,SAAd,EAEXJ,OAFW,CAAP,EAEM,GAAGC,IAFT,CAAP;AAGD;;;;AAEM,YAAMI,uBAAN,SAAsCb,oBAAtC,CAA2D;;AAE9D;AACA;AACA;AACAc,oBAAYP,IAAZ,EAAkB,GAAGQ,IAArB,EAA2B;AACvB,gBAAMR,IAAN,EAAY,GAAGQ,IAAf;AACAV,4BAAkBW,GAAlB,CAAsB,IAAtB;;AAEA,cAAGC,IAAIC,MAAJ,KAAeL,uBAAlB,EAA2C;AACvC,iBAAKM,aAAL;AACH;AACJ;;AAED;AACAC,iBAAS;AACL,eAAKC,eAAL;AACH;;AAEDC,kBAAU;AACRjB,4BAAkBkB,MAAlB,CAAyB,IAAzB;AACA,gBAAMD,OAAN;AACD;;AAEDE,iBAAS,GAAGT,IAAZ,EAAkB;AAChB,iBAAO,MAAMU,OAAN,CAAc,GAAGV,IAAjB,CAAP;AACD;;AAEDW,gBAAQ,GAAGX,IAAX,EAAiB;AACf,iBAAO,MAAMY,MAAN,CAAa,GAAGZ,IAAhB,CAAP;AACD;;AAEDU,gBAAQ,GAAGV,IAAX,EAAiB;AACf,gBAAMU,OAAN,CAAc,GAAGV,IAAjB;AACA,iBAAO,IAAP;AACD;;AAEDY,eAAO,GAAGZ,IAAV,EAAgB;AACd,gBAAMY,MAAN,CAAa,GAAGZ,IAAhB;AACA,iBAAO,IAAP;AACD;;AAEH;AACAa,sBAAc,GAAGC,MAAjB,EAAyB;AACvB,iBAAO,MAAMD,aAAN,CAAoB,GAAGxB,4CAA4C,GAAGyB,MAA/C,CAAvB,CAAP;AACD;AA7C+D;;;;;;;;;;6CAArDhB,wD;;;;;;;;AAgDN,eAASV,KAAT,CAAeI,IAAf,EAAqB,GAAGQ,IAAxB,EAA8B;AAAE,eAAO,IAAIF,uBAAJ,CAA4BN,IAA5B,EAAkC,GAAGQ,IAArC,CAAP;AAAoD;;AAE3F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;AACO,eAASb,KAAT,CAAe4B,WAAWzB,iBAA1B,EAA6C;AAChDyB,iBAASC,OAAT,CAAiB5B,SAASA,MAAM6B,cAAN,EAA1B;AACH;;AAED;AACA;AACA;;;;AACO,eAAS/B,6BAAT,GAAyC;AAC5CI,0BAAkB4B,KAAlB;AACH","file":"active-expression-ticking.js","sourcesContent":["import { BaseActiveExpression } from 'active-expression';\n\nconst TICKING_INSTANCES = new Set();\n\nexport function setExpressionOptionsForConventionStrategies(func, options = {}, ...rest) {\n  return [func, Object.assign({\n    checkImmediately: false\n  }, options), ...rest];\n}\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        TICKING_INSTANCES.add(this);\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    dispose() {\n      TICKING_INSTANCES.delete(this);\n      super.dispose();\n    }\n  \n    disable2(...args) {\n      return super.disable(...args)\n    }\n\n    enable2(...args) {\n      return super.enable(...args)\n    }\n  \n    disable(...args) {\n      super.disable(...args)\n      return this;\n    }\n\n    enable(...args) {\n      super.enable(...args)\n      return this;\n    }\n  \n  /** the parameter `checkImmediately` is by default false for convention strategies */\n  setExpression(...params) {\n    return super.setExpression(...setExpressionOptionsForConventionStrategies(...params))\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.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"]}