@ibyar/core 0.5.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/binding/binding.expressions.d.ts +3 -2
  2. package/binding/binding.expressions.js +45 -29
  3. package/binding/binding.expressions.js.map +1 -1
  4. package/component/component.js +8 -8
  5. package/component/component.js.map +1 -1
  6. package/component/provider.d.ts +5 -10
  7. package/component/provider.js +6 -31
  8. package/component/provider.js.map +1 -1
  9. package/context/stack.js +1 -1
  10. package/context/stack.js.map +1 -1
  11. package/context/subscription.d.ts +2 -0
  12. package/context/subscription.js +14 -0
  13. package/context/subscription.js.map +1 -0
  14. package/directive/directive.d.ts +7 -1
  15. package/directive/directive.js +7 -1
  16. package/directive/directive.js.map +1 -1
  17. package/directive/parser.d.ts +1 -1
  18. package/directive/parser.js +13 -10
  19. package/directive/parser.js.map +1 -1
  20. package/directive/providers.d.ts +2 -0
  21. package/directive/providers.js +4 -1
  22. package/directive/providers.js.map +1 -1
  23. package/html/expression.js +5 -4
  24. package/html/expression.js.map +1 -1
  25. package/index.d.ts +1 -0
  26. package/index.js +1 -0
  27. package/index.js.map +1 -1
  28. package/linker/change-detector-ref.d.ts +7 -0
  29. package/linker/change-detector-ref.js +32 -0
  30. package/linker/change-detector-ref.js.map +1 -0
  31. package/linker/template-ref.d.ts +5 -1
  32. package/linker/template-ref.js +13 -15
  33. package/linker/template-ref.js.map +1 -1
  34. package/linker/view-container-ref.d.ts +12 -10
  35. package/linker/view-container-ref.js +7 -7
  36. package/linker/view-container-ref.js.map +1 -1
  37. package/linker/view-ref.d.ts +4 -2
  38. package/linker/view-ref.js +9 -6
  39. package/linker/view-ref.js.map +1 -1
  40. package/package.json +6 -6
  41. package/pipe/pipe.d.ts +18 -8
  42. package/pipe/pipe.js +30 -15
  43. package/pipe/pipe.js.map +1 -1
  44. package/providers/provider.d.ts +1 -1
  45. package/providers/provider.js +2 -0
  46. package/providers/provider.js.map +1 -1
  47. package/render/host-listener.handler.d.ts +26 -0
  48. package/render/host-listener.handler.js +69 -0
  49. package/render/host-listener.handler.js.map +1 -0
  50. package/render/render-handler.d.ts +5 -0
  51. package/render/render-handler.js +2 -0
  52. package/render/render-handler.js.map +1 -0
  53. package/view/base-view.js +11 -22
  54. package/view/base-view.js.map +1 -1
  55. package/view/render.d.ts +16 -20
  56. package/view/render.js +84 -103
  57. package/view/render.js.map +1 -1
  58. package/view/view.js +6 -0
  59. package/view/view.js.map +1 -1
@@ -3,12 +3,13 @@ export class ViewRef {
3
3
  export class EmbeddedViewRef extends ViewRef {
4
4
  }
5
5
  export class EmbeddedViewRefImpl extends EmbeddedViewRef {
6
- constructor(_context, _rootNodes) {
6
+ constructor(_context, _rootNodes, _subscriptions) {
7
7
  super();
8
8
  this._context = _context;
9
9
  this._rootNodes = _rootNodes;
10
+ this._subscriptions = _subscriptions;
10
11
  this._destroyed = false;
11
- this.subscribes = [];
12
+ this.onDestroySubscribes = [];
12
13
  }
13
14
  get context() {
14
15
  return this._context;
@@ -27,10 +28,12 @@ export class EmbeddedViewRefImpl extends EmbeddedViewRef {
27
28
  }
28
29
  destroy() {
29
30
  if (!this._destroyed) {
31
+ this._subscriptions?.forEach(sub => sub.unsubscribe());
32
+ this._subscriptions?.splice(0, this._subscriptions.length);
30
33
  for (const node of this._rootNodes) {
31
34
  node.remove();
32
35
  }
33
- this.subscribes.forEach(callback => {
36
+ this.onDestroySubscribes.forEach(callback => {
34
37
  try {
35
38
  callback();
36
39
  }
@@ -61,12 +64,12 @@ export class EmbeddedViewRefImpl extends EmbeddedViewRef {
61
64
  }
62
65
  }
63
66
  onDestroy(callback) {
64
- this.subscribes.push(callback);
67
+ this.onDestroySubscribes.push(callback);
65
68
  return {
66
69
  unsubscribe: () => {
67
- const index = this.subscribes.indexOf(callback);
70
+ const index = this.onDestroySubscribes.indexOf(callback);
68
71
  if (index > -1) {
69
- this.subscribes.splice(index, 1);
72
+ this.onDestroySubscribes.splice(index, 1);
70
73
  }
71
74
  }
72
75
  };
@@ -1 +1 @@
1
- {"version":3,"file":"view-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AACA,MAAM,OAAgB,OAAO;CAmB5B;AAGD,MAAM,OAAgB,eAAkC,SAAQ,OAAO;CAwCtE;AAED,MAAM,OAAO,mBAAsC,SAAQ,eAAkB;IAK5E,YACS,QAAW,EACX,UAAkB;QAC1B,KAAK,EAAE,CAAC;QAFA,aAAQ,GAAR,QAAQ,CAAG;QACX,eAAU,GAAV,UAAU,CAAQ;QALnB,eAAU,GAAY,KAAK,CAAC;QAC5B,eAAU,GAAmB,EAAE,CAAC;IAMxC,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IACD,IAAI,KAAK;QACR,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAY,CAAC;IACtC,CAAC;IACD,IAAI,IAAI;QACP,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAY,CAAC;IAC/D,CAAC;IACD,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IACD,OAAO;QACN,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YACrB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;gBACzB,IAAK,CAAC,MAAM,EAAE,CAAC;aACzB;YACD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAClC,IAAI;oBACH,QAAQ,EAAE,CAAC;iBACX;gBAAC,OAAO,KAAK,EAAE;oBACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACrB;YACF,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;SACvB;IACF,CAAC;IACO,UAAU;QACjB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,EAAE;YAChC,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;SAC1B;QACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;QACnD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACvD,OAAO,QAAQ,CAAC;IACjB,CAAC;IACD,KAAK,CAAC,IAAe;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,CAAC,IAAe;QACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAChC,CAAC;IACD,MAAM;QACL,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YACzB,IAAK,CAAC,MAAM,EAAE,CAAC;SACzB;IACF,CAAC;IACD,SAAS,CAAC,QAAoB;QAC7B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,OAAO;YACN,WAAW,EAAE,GAAG,EAAE;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAChD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;oBACf,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBACjC;YACF,CAAC;SACD,CAAC;IACH,CAAC;CAED","sourcesContent":["\nexport abstract class ViewRef {\n\t/**\n\t * Destroys this view and all of the data structures associated with it.\n\t */\n\tabstract destroy(): void;\n\n\t/**\n\t * Reports whether this view has been destroyed.\n\t * @returns True after the `destroy()` method has been called, false otherwise.\n\t */\n\tabstract get destroyed(): boolean;\n\n\t/**\n\t * A lifecycle hook that provides additional developer-defined cleanup\n\t * functionality for views.\n\t * @param callback A handler function that cleans up developer-defined data\n\t * associated with a view. Called when the `destroy()` method is invoked.\n\t */\n\tabstract onDestroy(callback: Function): { unsubscribe(): void };\n}\n\n\nexport abstract class EmbeddedViewRef<C extends object> extends ViewRef {\n\t/**\n\t * The context for this view, inherited from the anchor element.\n\t */\n\tabstract get context(): C;\n\n\t/**\n\t * The root nodes for this embedded view.\n\t */\n\tabstract get rootNodes(): Node[];\n\n\t/**\n\t * the first node for this embedded view.\n\t */\n\tabstract get first(): ChildNode;\n\n\t/**\n\t * the last node for this embedded view.\n\t */\n\tabstract get last(): ChildNode;\n\n\t/**\n\t * insert view after the node.\n\t * @param node \n\t */\n\tabstract after(node: ChildNode): void;\n\n\t/**\n\t * insert view before the node.\n\t * @param node \n\t */\n\tabstract before(node: ChildNode): void;\n\n\t/**\n\t * remove the root nodes from the view, but keep reference to them.\n\t * \n\t * Detaches a view from this container without destroying it.\n\t * Use along with after()/before() to move a view within the current container.\n\t */\n\tabstract detach(): void;\n}\n\nexport class EmbeddedViewRefImpl<C extends object> extends EmbeddedViewRef<C> {\n\n\tprivate _destroyed: boolean = false;\n\tprivate subscribes: (() => void)[] = [];\n\n\tconstructor(\n\t\tprivate _context: C,\n\t\tprivate _rootNodes: Node[]) {\n\t\tsuper();\n\t}\n\n\tget context(): C {\n\t\treturn this._context;\n\t}\n\n\tget rootNodes(): Node[] {\n\t\treturn this._rootNodes;\n\t}\n\tget first(): Element {\n\t\treturn this._rootNodes[0] as Element;\n\t}\n\tget last(): Element {\n\t\treturn this._rootNodes[this._rootNodes.length - 1] as Element;\n\t}\n\tget destroyed(): boolean {\n\t\treturn this._destroyed;\n\t}\n\tdestroy(): void {\n\t\tif (!this._destroyed) {\n\t\t\tfor (const node of this._rootNodes) {\n\t\t\t\t(<Element>node).remove();\n\t\t\t}\n\t\t\tthis.subscribes.forEach(callback => {\n\t\t\t\ttry {\n\t\t\t\t\tcallback();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._destroyed = true;\n\t\t}\n\t}\n\tprivate getAsANode() {\n\t\tif (this._rootNodes.length == 1) {\n\t\t\treturn this._rootNodes[0];\n\t\t}\n\t\tconst fragment = document.createDocumentFragment();\n\t\tthis._rootNodes.forEach(node => fragment.append(node));\n\t\treturn fragment;\n\t}\n\tafter(node: ChildNode): void {\n\t\tnode.after(this.getAsANode());\n\t}\n\tbefore(node: ChildNode): void {\n\t\tnode.before(this.getAsANode());\n\t}\n\tdetach(): void {\n\t\tfor (const node of this._rootNodes) {\n\t\t\t(<Element>node).remove();\n\t\t}\n\t}\n\tonDestroy(callback: () => void): { unsubscribe(): void; } {\n\t\tthis.subscribes.push(callback);\n\t\treturn {\n\t\t\tunsubscribe: () => {\n\t\t\t\tconst index = this.subscribes.indexOf(callback);\n\t\t\t\tif (index > -1) {\n\t\t\t\t\tthis.subscribes.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n}\n"]}
1
+ {"version":3,"file":"view-ref.js","sourceRoot":"","sources":["../../../src/core/linker/view-ref.ts"],"names":[],"mappings":"AAEA,MAAM,OAAgB,OAAO;CAmB5B;AAGD,MAAM,OAAgB,eAAkC,SAAQ,OAAO;CAwCtE;AAED,MAAM,OAAO,mBAAsC,SAAQ,eAAkB;IAK5E,YACS,QAAW,EACX,UAAkB,EAClB,cAAkD;QAC1D,KAAK,EAAE,CAAC;QAHA,aAAQ,GAAR,QAAQ,CAAG;QACX,eAAU,GAAV,UAAU,CAAQ;QAClB,mBAAc,GAAd,cAAc,CAAoC;QANnD,eAAU,GAAY,KAAK,CAAC;QAC5B,wBAAmB,GAAmB,EAAE,CAAC;IAOjD,CAAC;IAED,IAAI,OAAO;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC;IACtB,CAAC;IAED,IAAI,SAAS;QACZ,OAAO,IAAI,CAAC,UAAU,CAA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jB,CAAC;IACD,KAAK,CAAC,IAAe;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAC/B,CAAC;IACD,MAAM,CAAC,IAAe;QACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC;IAChC,CAAC;IACD,MAAM;QACL,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;YACzB,IAAK,CAAC,MAAM,EAAE,CAAC;SACzB;IACF,CAAC;IACD,SAAS,CAAC,QAAoB;QAC7B,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,OAAO;YACN,WAAW,EAAE,GAAG,EAAE;gBACjB,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBACzD,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE;oBACf,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBAC1C;YACF,CAAC;SACD,CAAC;IACH,CAAC;CAED","sourcesContent":["import { ScopeContext, ScopeSubscription } from '@ibyar/expressions';\n\nexport abstract class ViewRef {\n\t/**\n\t * Destroys this view and all of the data structures associated with it.\n\t */\n\tabstract destroy(): void;\n\n\t/**\n\t * Reports whether this view has been destroyed.\n\t * @returns True after the `destroy()` method has been called, false otherwise.\n\t */\n\tabstract get destroyed(): boolean;\n\n\t/**\n\t * A lifecycle hook that provides additional developer-defined cleanup\n\t * functionality for views.\n\t * @param callback A handler function that cleans up developer-defined data\n\t * associated with a view. Called when the `destroy()` method is invoked.\n\t */\n\tabstract onDestroy(callback: Function): { unsubscribe(): void };\n}\n\n\nexport abstract class EmbeddedViewRef<C extends object> extends ViewRef {\n\t/**\n\t * The context for this view, inherited from the anchor element.\n\t */\n\tabstract get context(): C;\n\n\t/**\n\t * The root nodes for this embedded view.\n\t */\n\tabstract get rootNodes(): Node[];\n\n\t/**\n\t * the first node for this embedded view.\n\t */\n\tabstract get first(): ChildNode;\n\n\t/**\n\t * the last node for this embedded view.\n\t */\n\tabstract get last(): ChildNode;\n\n\t/**\n\t * insert view after the node.\n\t * @param node \n\t */\n\tabstract after(node: ChildNode): void;\n\n\t/**\n\t * insert view before the node.\n\t * @param node \n\t */\n\tabstract before(node: ChildNode): void;\n\n\t/**\n\t * remove the root nodes from the view, but keep reference to them.\n\t * \n\t * Detaches a view from this container without destroying it.\n\t * Use along with after()/before() to move a view within the current container.\n\t */\n\tabstract detach(): void;\n}\n\nexport class EmbeddedViewRefImpl<C extends object> extends EmbeddedViewRef<C> {\n\n\tprivate _destroyed: boolean = false;\n\tprivate onDestroySubscribes: (() => void)[] = [];\n\n\tconstructor(\n\t\tprivate _context: C,\n\t\tprivate _rootNodes: Node[],\n\t\tprivate _subscriptions?: ScopeSubscription<ScopeContext>[]) {\n\t\tsuper();\n\t}\n\n\tget context(): C {\n\t\treturn this._context;\n\t}\n\n\tget rootNodes(): Node[] {\n\t\treturn this._rootNodes;\n\t}\n\tget first(): Element {\n\t\treturn this._rootNodes[0] as Element;\n\t}\n\tget last(): Element {\n\t\treturn this._rootNodes[this._rootNodes.length - 1] as Element;\n\t}\n\tget destroyed(): boolean {\n\t\treturn this._destroyed;\n\t}\n\tdestroy(): void {\n\t\tif (!this._destroyed) {\n\t\t\tthis._subscriptions?.forEach(sub => sub.unsubscribe());\n\t\t\tthis._subscriptions?.splice(0, this._subscriptions.length);\n\t\t\tfor (const node of this._rootNodes) {\n\t\t\t\t(<Element>node).remove();\n\t\t\t}\n\t\t\tthis.onDestroySubscribes.forEach(callback => {\n\t\t\t\ttry {\n\t\t\t\t\tcallback();\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconsole.error(error);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis._destroyed = true;\n\t\t}\n\t}\n\tprivate getAsANode() {\n\t\tif (this._rootNodes.length == 1) {\n\t\t\treturn this._rootNodes[0];\n\t\t}\n\t\tconst fragment = document.createDocumentFragment();\n\t\tthis._rootNodes.forEach(node => fragment.append(node));\n\t\treturn fragment;\n\t}\n\tafter(node: ChildNode): void {\n\t\tnode.after(this.getAsANode());\n\t}\n\tbefore(node: ChildNode): void {\n\t\tnode.before(this.getAsANode());\n\t}\n\tdetach(): void {\n\t\tfor (const node of this._rootNodes) {\n\t\t\t(<Element>node).remove();\n\t\t}\n\t}\n\tonDestroy(callback: () => void): { unsubscribe(): void; } {\n\t\tthis.onDestroySubscribes.push(callback);\n\t\treturn {\n\t\t\tunsubscribe: () => {\n\t\t\t\tconst index = this.onDestroySubscribes.indexOf(callback);\n\t\t\t\tif (index > -1) {\n\t\t\t\t\tthis.onDestroySubscribes.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibyar/core",
3
- "version": "0.5.0",
3
+ "version": "0.5.4",
4
4
  "description": "Implements Aurora's core functionality, low-level services, and utilities",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ibyar/aurora/tree/dev/packages/core",
@@ -23,13 +23,13 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@ibyar/elements": "^0.5.0",
27
- "@ibyar/expressions": "^0.5.0",
26
+ "@ibyar/elements": "^0.5.4",
27
+ "@ibyar/expressions": "^0.5.4",
28
28
  "reflect-metadata": "^0.1.13",
29
- "tslib": "^2.3.1"
29
+ "tslib": "^2.4.0"
30
30
  },
31
31
  "devDependencies": {
32
- "typescript": "^4.5.2"
32
+ "typescript": "^4.6.4"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsc --build --verbose"
@@ -62,5 +62,5 @@
62
62
  "interceptor",
63
63
  "typescript"
64
64
  ],
65
- "gitHead": "2b67ab6bafaaf8bf796c2a5de13d745034381dfb"
65
+ "gitHead": "0e62f914850836abc384d26c9f94a7b8389a2c0d"
66
66
  }
package/pipe/pipe.d.ts CHANGED
@@ -1,10 +1,15 @@
1
- import { ReactiveScope, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';
2
- import { OnDestroy } from '../index.js';
1
+ import { ReactiveScopeControl, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';
2
+ import { OnDestroy } from '../component/lifecycle.js';
3
+ import { ChangeDetectorRef } from '../linker/change-detector-ref.js';
4
+ import { TypeOf } from '../utils/typeof.js';
3
5
  export interface PipeTransform<T, U> {
4
6
  transform(value: T, ...args: any[]): U;
5
7
  }
6
- export interface AsyncPipeTransform<T, U> extends PipeTransform<T, U>, OnDestroy {
7
- subscribe(callback: (value: U) => void): void;
8
+ export declare abstract class AsyncPipeTransform<T, U> implements PipeTransform<T, U>, OnDestroy {
9
+ protected changeDetectorRef: ChangeDetectorRef;
10
+ constructor(changeDetectorRef: ChangeDetectorRef);
11
+ abstract transform(value: T, ...args: any[]): U;
12
+ abstract onDestroy(): void;
8
13
  }
9
14
  export declare function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U>;
10
15
  export declare class PipeProvider extends ReadOnlyScope<{
@@ -13,19 +18,24 @@ export declare class PipeProvider extends ReadOnlyScope<{
13
18
  constructor();
14
19
  has(pipeName: string): boolean;
15
20
  get(pipeName: string): any;
21
+ getClass(): TypeOf<PipeProvider>;
16
22
  }
17
23
  export declare class AsyncPipeProvider extends ReadOnlyScope<object> {
18
- static AsyncPipeContext: any;
19
24
  constructor();
20
25
  has(pipeName: string): boolean;
21
- get(pipeName: string): PipeTransform<any, any> | undefined;
26
+ get(pipeName: string): TypeOf<AsyncPipeTransform<any, any>> | undefined;
27
+ getClass(): TypeOf<AsyncPipeProvider>;
22
28
  }
23
29
  export declare class AsyncPipeScope<T extends {
24
30
  [key: string]: AsyncPipeTransform<any, any>;
25
- }> extends ReactiveScope<T> {
31
+ }> extends ReactiveScopeControl<T> {
32
+ static blockScope<P extends {
33
+ [key: string]: AsyncPipeTransform<any, any>;
34
+ }>(): AsyncPipeScope<P>;
26
35
  private wrapper;
27
36
  constructor();
28
- set(propertyKey: keyof T, newValue: any, receiver?: any): boolean;
37
+ set(propertyKey: keyof T, pipeClass: TypeOf<AsyncPipeTransform<any, any>>, receiver?: any): boolean;
29
38
  get(propertyKey: keyof T): any;
30
39
  unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
40
+ getClass(): TypeOf<AsyncPipeScope<T>>;
31
41
  }
package/pipe/pipe.js CHANGED
@@ -1,11 +1,17 @@
1
- import { ReactiveScope, ReadOnlyScope } from '@ibyar/expressions';
1
+ import { ReactiveScopeControl, ReadOnlyScope } from '@ibyar/expressions';
2
+ import { createChangeDetectorRef } from '../linker/change-detector-ref.js';
2
3
  import { ClassRegistryProvider } from '../providers/provider.js';
4
+ export class AsyncPipeTransform {
5
+ constructor(changeDetectorRef) {
6
+ this.changeDetectorRef = changeDetectorRef;
7
+ }
8
+ }
3
9
  export function isPipeTransform(pipe) {
4
10
  return Reflect.has(Object.getPrototypeOf(pipe), 'transform');
5
11
  }
6
12
  export class PipeProvider extends ReadOnlyScope {
7
13
  constructor() {
8
- super({}, 'block');
14
+ super({});
9
15
  }
10
16
  has(pipeName) {
11
17
  if (pipeName in this.context) {
@@ -28,10 +34,13 @@ export class PipeProvider extends ReadOnlyScope {
28
34
  }
29
35
  return void 0;
30
36
  }
37
+ getClass() {
38
+ return PipeProvider;
39
+ }
31
40
  }
32
41
  export class AsyncPipeProvider extends ReadOnlyScope {
33
42
  constructor() {
34
- super(AsyncPipeProvider.AsyncPipeContext, 'block');
43
+ super({});
35
44
  }
36
45
  has(pipeName) {
37
46
  const pipeRef = ClassRegistryProvider.getPipe(pipeName);
@@ -40,24 +49,27 @@ export class AsyncPipeProvider extends ReadOnlyScope {
40
49
  get(pipeName) {
41
50
  const pipeRef = ClassRegistryProvider.getPipe(pipeName);
42
51
  if (pipeRef?.asynchronous) {
43
- return new pipeRef.modelClass();
52
+ return pipeRef.modelClass;
44
53
  }
45
- return void 0;
54
+ return;
55
+ }
56
+ getClass() {
57
+ return AsyncPipeProvider;
46
58
  }
47
59
  }
48
- AsyncPipeProvider.AsyncPipeContext = Object.create(null);
49
- export class AsyncPipeScope extends ReactiveScope {
60
+ export class AsyncPipeScope extends ReactiveScopeControl {
50
61
  constructor() {
51
- super({}, 'block');
62
+ super({});
52
63
  this.wrapper = {};
53
64
  }
54
- set(propertyKey, newValue, receiver) {
55
- const result = super.set(propertyKey, newValue, receiver);
65
+ static blockScope() {
66
+ return new AsyncPipeScope();
67
+ }
68
+ set(propertyKey, pipeClass, receiver) {
69
+ const detector = createChangeDetectorRef(this, propertyKey);
70
+ const pipe = new pipeClass(detector);
71
+ const result = super.set(propertyKey, pipe, receiver);
56
72
  if (result) {
57
- const pipe = this.context[propertyKey];
58
- pipe.subscribe(value => {
59
- this.emit(propertyKey, value);
60
- });
61
73
  this.wrapper[propertyKey] = (value, ...args) => {
62
74
  return pipe.transform(value, ...args);
63
75
  };
@@ -68,9 +80,12 @@ export class AsyncPipeScope extends ReactiveScope {
68
80
  return Reflect.get(this.wrapper, propertyKey);
69
81
  }
70
82
  unsubscribe(propertyKey, subscription) {
71
- this.unsubscribe(propertyKey, subscription);
83
+ super.unsubscribe(propertyKey, subscription);
72
84
  const pipe = this.context[propertyKey];
73
85
  pipe.onDestroy();
74
86
  }
87
+ getClass() {
88
+ return AsyncPipeScope;
89
+ }
75
90
  }
76
91
  //# sourceMappingURL=pipe.js.map
package/pipe/pipe.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../src/core/pipe/pipe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AAErF,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAiBjE,MAAM,UAAU,eAAe,CAA+B,IAAS;IACtE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CA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W,CAAC,CAAC;IAC/C,CAAC;IACQ,WAAW,CAAC,WAAoB,EAAE,YAAmC;QAC7E,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["import { ReactiveScope, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';\nimport { isOnDestroy, OnDestroy } from '../index.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\n\n/**\n * Pipes are used as singleton\n * it will be created if it needed, had no life cycle\n * \n * * no dependency injection applied on filters for now,\n * TODO: add support of dependency injection\n */\nexport interface PipeTransform<T, U> {\n\ttransform(value: T, ...args: any[]): U;\n}\n\nexport interface AsyncPipeTransform<T, U> extends PipeTransform<T, U>, OnDestroy {\n\tsubscribe(callback: (value: U) => void): void;\n}\n\nexport function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U> {\n\treturn Reflect.has(Object.getPrototypeOf(pipe), 'transform');\n}\n\nexport class PipeProvider extends ReadOnlyScope<{ [pipeName: string]: Function }> {\n\tconstructor() {\n\t\tsuper({}, 'block');\n\t}\n\thas(pipeName: string): boolean {\n\t\tif (pipeName in this.context) {\n\t\t\treturn true;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef !== undefined && !pipeRef.asynchronous;\n\t}\n\tget(pipeName: string): any {\n\t\tlet transformFunc: Function | undefined;\n\t\tif (transformFunc = this.context[pipeName]) {\n\t\t\treturn transformFunc;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef !== undefined && !pipeRef.asynchronous) {\n\t\t\tconst pipe = new pipeRef.modelClass();\n\t\t\ttransformFunc = (value: any, ...args: any[]) => pipe.transform(value, ...args);\n\t\t\tthis.context[pipeRef.name] = transformFunc;\n\t\t\treturn transformFunc;\n\t\t}\n\t\treturn void 0;\n\t}\n}\n\nexport class AsyncPipeProvider extends ReadOnlyScope<object> {\n\n\tstatic AsyncPipeContext = Object.create(null);\n\tconstructor() {\n\t\tsuper(AsyncPipeProvider.AsyncPipeContext, 'block');\n\t}\n\thas(pipeName: string): boolean {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef?.asynchronous ? true : false;\n\t}\n\tget(pipeName: string): PipeTransform<any, any> | undefined {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef?.asynchronous) {\n\t\t\treturn new pipeRef.modelClass();\n\t\t}\n\t\treturn void 0;\n\t}\n}\n\nexport class AsyncPipeScope<T extends { [key: string]: AsyncPipeTransform<any, any> }> extends ReactiveScope<T> {\n\tprivate wrapper: { [key: string]: Function } = {};\n\tconstructor() {\n\t\tsuper({} as T, 'block');\n\t}\n\toverride set(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst result = super.set(propertyKey, newValue, receiver);\n\t\tif (result) {\n\t\t\tconst pipe = this.context[propertyKey];\n\t\t\tpipe.subscribe(value => {\n\t\t\t\tthis.emit(propertyKey, value);\n\t\t\t});\n\t\t\tthis.wrapper[propertyKey as string] = (value: any, ...args: any[]) => {\n\t\t\t\treturn pipe.transform(value, ...args)\n\t\t\t};\n\t\t}\n\t\treturn result;\n\t}\n\toverride get(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.wrapper, propertyKey);\n\t}\n\toverride unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tthis.unsubscribe(propertyKey, subscription);\n\t\tconst pipe = this.context[propertyKey];\n\t\tpipe.onDestroy();\n\t}\n}\n"]}
1
+ {"version":3,"file":"pipe.js","sourceRoot":"","sources":["../../../src/core/pipe/pipe.ts"],"names":[],"mappings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AAM,EAAE;YACX,IAAI,CAAC,OAAO,CAAC,WAAqB,CAAC,GAAG,CAAC,KAAU,EAAE,GAAG,IAAW,EAAE,EAAE;gBACpE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAA;YACtC,CAAC,CAAC;SACF;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IACQ,GAAG,CAAC,WAAoB;QAChC,OAAO,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAC/C,CAAC;IACQ,WAAW,CAAC,WAAoB,EAAE,YAAmC;QAC7E,KAAK,CAAC,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACvC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;IACD,QAAQ;QACP,OAAO,cAAc,CAAC;IACvB,CAAC;CACD","sourcesContent":["import { ReactiveScopeControl, ReadOnlyScope, ScopeSubscription } from '@ibyar/expressions';\nimport { OnDestroy } from '../component/lifecycle.js';\nimport { ChangeDetectorRef, createChangeDetectorRef } from '../linker/change-detector-ref.js';\nimport { ClassRegistryProvider } from '../providers/provider.js';\nimport { TypeOf } from '../utils/typeof.js';\n\n/**\n * Pipes are used as singleton\n * it will be created if it needed, had no life cycle\n * \n * * no dependency injection applied on filters for now,\n * TODO: add support of dependency injection\n */\nexport interface PipeTransform<T, U> {\n\ttransform(value: T, ...args: any[]): U;\n}\n\nexport abstract class AsyncPipeTransform<T, U> implements PipeTransform<T, U>, OnDestroy {\n\tconstructor(protected changeDetectorRef: ChangeDetectorRef) { }\n\tabstract transform(value: T, ...args: any[]): U;\n\tabstract onDestroy(): void;\n}\n\nexport function isPipeTransform<T extends any, U extends any>(pipe: any): pipe is PipeTransform<T, U> {\n\treturn Reflect.has(Object.getPrototypeOf(pipe), 'transform');\n}\n\nexport class PipeProvider extends ReadOnlyScope<{ [pipeName: string]: Function }> {\n\tconstructor() {\n\t\tsuper({});\n\t}\n\thas(pipeName: string): boolean {\n\t\tif (pipeName in this.context) {\n\t\t\treturn true;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef !== undefined && !pipeRef.asynchronous;\n\t}\n\tget(pipeName: string): any {\n\t\tlet transformFunc: Function | undefined;\n\t\tif (transformFunc = this.context[pipeName]) {\n\t\t\treturn transformFunc;\n\t\t}\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<PipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef !== undefined && !pipeRef.asynchronous) {\n\t\t\tconst pipe = new pipeRef.modelClass();\n\t\t\ttransformFunc = (value: any, ...args: any[]) => pipe.transform(value, ...args);\n\t\t\tthis.context[pipeRef.name] = transformFunc;\n\t\t\treturn transformFunc;\n\t\t}\n\t\treturn void 0;\n\t}\n\tgetClass(): TypeOf<PipeProvider> {\n\t\treturn PipeProvider;\n\t}\n}\n\nexport class AsyncPipeProvider extends ReadOnlyScope<object> {\n\tconstructor() {\n\t\tsuper({});\n\t}\n\thas(pipeName: string): boolean {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<AsyncPipeTransform<any, any>>(pipeName);\n\t\treturn pipeRef?.asynchronous ? true : false;\n\t}\n\tget(pipeName: string): TypeOf<AsyncPipeTransform<any, any>> | undefined {\n\t\tconst pipeRef = ClassRegistryProvider.getPipe<AsyncPipeTransform<any, any>>(pipeName);\n\t\tif (pipeRef?.asynchronous) {\n\t\t\treturn pipeRef.modelClass;\n\t\t}\n\t\treturn;\n\t}\n\tgetClass(): TypeOf<AsyncPipeProvider> {\n\t\treturn AsyncPipeProvider;\n\t}\n}\n\nexport class AsyncPipeScope<T extends { [key: string]: AsyncPipeTransform<any, any> }> extends ReactiveScopeControl<T> {\n\tstatic blockScope<P extends { [key: string]: AsyncPipeTransform<any, any> }>(): AsyncPipeScope<P> {\n\t\treturn new AsyncPipeScope();\n\t}\n\tprivate wrapper: { [key: string]: Function } = {};\n\tconstructor() {\n\t\tsuper({} as T);\n\t}\n\toverride set(propertyKey: keyof T, pipeClass: TypeOf<AsyncPipeTransform<any, any>>, receiver?: any): boolean {\n\t\tconst detector = createChangeDetectorRef(this, propertyKey);\n\t\tconst pipe = new pipeClass(detector);\n\t\tconst result = super.set(propertyKey, pipe, receiver);\n\t\tif (result) {\n\t\t\tthis.wrapper[propertyKey as string] = (value: any, ...args: any[]) => {\n\t\t\t\treturn pipe.transform(value, ...args)\n\t\t\t};\n\t\t}\n\t\treturn result;\n\t}\n\toverride get(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.wrapper, propertyKey);\n\t}\n\toverride unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tsuper.unsubscribe(propertyKey, subscription);\n\t\tconst pipe = this.context[propertyKey];\n\t\tpipe.onDestroy();\n\t}\n\tgetClass(): TypeOf<AsyncPipeScope<T>> {\n\t\treturn AsyncPipeScope;\n\t}\n}\n"]}
@@ -14,7 +14,7 @@ export declare class ClassRegistry {
14
14
  hasComponent<T>(selector: string): boolean;
15
15
  getComponentRef<T>(selector: string): ComponentRef<T> | undefined;
16
16
  getComponent<T>(selector: string): Function | undefined;
17
- getComponentView(selector: string): (import("../utils/typeof.js").TypeOf<import("../index.js").HTMLComponent<unknown>> & CustomElementConstructor) | undefined;
17
+ getComponentView(selector: string): (import("../index.js").TypeOf<import("../index.js").HTMLComponent<unknown>> & CustomElementConstructor) | undefined;
18
18
  hasOutput<T>(model: Object, eventName: string): PropertyRef | false;
19
19
  hasInput<T>(model: Object, eventName: string): PropertyRef | false;
20
20
  hasDirective<T>(selector: string): boolean;
@@ -38,6 +38,7 @@ export class ClassRegistry {
38
38
  return componentRef;
39
39
  }
40
40
  }
41
+ return;
41
42
  }
42
43
  getComponent(selector) {
43
44
  for (const modelClass of this.componentSet) {
@@ -46,6 +47,7 @@ export class ClassRegistry {
46
47
  return modelClass;
47
48
  }
48
49
  }
50
+ return;
49
51
  }
50
52
  getComponentView(selector) {
51
53
  return this.getComponentRef(selector)?.viewClass;
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/providers/provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,UAAU,EAEV,MAAM,2BAA2B,CAAC;AAGnC,MAAM,OAAO,aAAa;IAA1B;QACC,YAAO,GAAkB,IAAI,GAAG,EAAE,CAAC;QACnC,iBAAY,GAAkB,IAAI,GAAG,EAAE,CAAC;QACxC,eAAU,GAAkB,IAAI,GAAG,EAAE,CAAC;QACtC,iBAAY,GAAkB,IAAI,GAAG,EAAE,CAAC;QACxC,YAAO,GAAkB,IAAI,GAAG,EAAE,CAAC;IAkIpC,CAAC;IAhIA,YAAY,CAAC,QAAkB;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IACD,iBAAiB,CAAC,QAAkB;QACnC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,eAAe,CAAC,QAAkB;QACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IACD,iBAAiB,CAAC,QAAkB;QACnC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,YAAY,CAAC,QAAkB;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,YAAY,CAAI,QAAgB;QAC/B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;YAC3C,MAAM,YAAY,GAAoB,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YAC7E,IAAI,YAAY,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACvC,OAAO,IAAI,CAAC;aACZ;SACD;Q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SAAS,CAAC,CAAC;YACxF,IAAI,YAAY,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACvC,OAAO,YAAY,CAAC;aACpB;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAGD,OAAO,CAAI,QAAgB;QAC1B,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,MAAM,OAAO,GAAe,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACzE,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC9B,OAAO,OAAO,CAAC;aACf;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,UAAU,CAAI,WAAmB;QAChC,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE;YAC3C,MAAM,UAAU,GAAkB,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAClF,IAAI,UAAU,CAAC,IAAI,KAAK,WAAW,EAAE;gBACpC,OAAO,UAAU,CAAC;aAClB;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["\nimport {\n\tComponents, ComponentRef, DirectiveRef,\n\tPipeRef, PropertyRef, ServiceRef\n} from '../component/component.js';\nexport type ProviderType = 'component' | 'service' | 'directive' | 'pipe' | 'self';\n\nexport class ClassRegistry {\n\tviewSet: Set<Function> = new Set();\n\tcomponentSet: Set<Function> = new Set();\n\tserviceSet: Set<Function> = new Set();\n\tdirectiveSet: Set<Function> = new Set();\n\tpipeSet: Set<Function> = new Set();\n\n\tregisterView(classRef: Function): void {\n\t\tthis.viewSet.add(classRef);\n\t}\n\tregisterComponent(classRef: Function): void {\n\t\tthis.componentSet.add(classRef);\n\t}\n\tregisterService(classRef: Function): void {\n\t\tthis.serviceSet.add(classRef);\n\t}\n\tregisterDirective(classRef: Function): void {\n\t\tthis.directiveSet.add(classRef);\n\t}\n\tregisterPipe(classRef: Function): void {\n\t\tthis.pipeSet.add(classRef);\n\t}\n\n\thasComponent<T>(selector: string): boolean {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tgetComponentRef<T>(selector: string): ComponentRef<T> | undefined {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn componentRef;\n\t\t\t}\n\t\t}\n\t}\n\n\tgetComponent<T>(selector: string) {\n\t\t// this.componentSet.\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn modelClass;\n\t\t\t}\n\t\t}\n\t}\n\n\tgetComponentView(selector: string) {\n\t\treturn this.getComponentRef(selector)?.viewClass;\n\t}\n\n\thasOutput<T>(model: Object, eventName: string): PropertyRef | false {\n\t\tif (Reflect.has(model, 'bootstrap')) {\n\t\t\tconst componentRef: ComponentRef<T> = Reflect.get(model, 'bootstrap');\n\t\t\tif (componentRef.outputs) {\n\t\t\t\tfor (const out of componentRef.outputs) {\n\t\t\t\t\tif (out.viewAttribute === eventName) {\n\t\t\t\t\t\treturn out;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\thasInput<T>(model: Object, eventName: string): PropertyRef | false {\n\t\tif (Reflect.has(model, 'bootstrap')) {\n\t\t\tconst componentRef: ComponentRef<T> = Reflect.get(model, 'bootstrap');\n\t\t\tif (componentRef.inputs) {\n\t\t\t\tfor (const input of componentRef.inputs) {\n\t\t\t\t\tif (input.viewAttribute === eventName) {\n\t\t\t\t\t\treturn input;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\thasDirective<T>(selector: string): boolean {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif (directiveRef.selector === selector) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tdirectiveHasInput<T>(input: string, directiveType: 'attributes' | 'structural' = 'attributes'): boolean {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif ((directiveType === 'attributes' && !directiveRef.selector.startsWith('*'))\n\t\t\t\t|| (directiveType === 'structural' && directiveRef.selector.startsWith('*'))) {\n\t\t\t\tif (directiveRef.inputs?.filter(ref => ref.viewAttribute === input).length > 0) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tgetDirectiveRef<T>(selector: string): DirectiveRef<T> | undefined {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif (directiveRef.selector === selector) {\n\t\t\t\treturn directiveRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\n\tgetPipe<T>(pipeName: string): PipeRef<T> | undefined {\n\t\tfor (const pipeClass of this.pipeSet) {\n\t\t\tconst pipeRef: PipeRef<T> = Components.getBootstrap(pipeClass.prototype);\n\t\t\tif (pipeRef.name === pipeName) {\n\t\t\t\treturn pipeRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tgetService<T>(serviceName: string): ServiceRef<T> | undefined {\n\t\tfor (const serviceClass of this.serviceSet) {\n\t\t\tconst serviceRef: ServiceRef<T> = Components.getBootstrap(serviceClass.prototype);\n\t\t\tif (serviceRef.name === serviceName) {\n\t\t\t\treturn serviceRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n}\n\nexport const ClassRegistryProvider = new ClassRegistry();\n"]}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/core/providers/provider.ts"],"names":[],"mappings":"AACA,OAAO,EACN,UAAU,EAEV,MAAM,2BAA2B,CAAC;AAGnC,MAAM,OAAO,aAAa;IAA1B;QACC,YAAO,GAAkB,IAAI,GAAG,EAAE,CAAC;QACnC,iBAAY,GAAkB,IAAI,GAAG,EAAE,CAAC;QACxC,eAAU,GAAkB,IAAI,GAAG,EAAE,CAAC;QACtC,iBAAY,GAAkB,IAAI,GAAG,EAAE,CAAC;QACxC,YAAO,GAAkB,IAAI,GAAG,EAAE,CAAC;IAmIpC,CAAC;IAjIA,YAAY,CAAC,QAAkB;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IACD,iBAAiB,CAAC,QAAkB;QACnC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,eAAe,CAAC,QAAkB;QACjC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IACD,iBAAiB,CAAC,QAAkB;QACnC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IACD,YAAY,CAAC,QAAkB;QAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,YAAY,CAAI,QAAgB;QAC/B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,YAAY,EAAE;YAC3C,MAAM,YAAY,GAAoB,UAAU,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC;YAC7E,IAAI,YAAY,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACvC,OAAO,IAAI,CAAC;aACZ;SAC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,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;YACxF,IAAI,YAAY,CAAC,QAAQ,KAAK,QAAQ,EAAE;gBACvC,OAAO,YAAY,CAAC;aACpB;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAGD,OAAO,CAAI,QAAgB;QAC1B,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,MAAM,OAAO,GAAe,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACzE,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;gBAC9B,OAAO,OAAO,CAAC;aACf;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,UAAU,CAAI,WAAmB;QAChC,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,UAAU,EAAE;YAC3C,MAAM,UAAU,GAAkB,UAAU,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAClF,IAAI,UAAU,CAAC,IAAI,KAAK,WAAW,EAAE;gBACpC,OAAO,UAAU,CAAC;aAClB;SACD;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;CACD;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,aAAa,EAAE,CAAC","sourcesContent":["\nimport {\n\tComponents, ComponentRef, DirectiveRef,\n\tPipeRef, PropertyRef, ServiceRef\n} from '../component/component.js';\nexport type ProviderType = 'component' | 'service' | 'directive' | 'pipe' | 'self';\n\nexport class ClassRegistry {\n\tviewSet: Set<Function> = new Set();\n\tcomponentSet: Set<Function> = new Set();\n\tserviceSet: Set<Function> = new Set();\n\tdirectiveSet: Set<Function> = new Set();\n\tpipeSet: Set<Function> = new Set();\n\n\tregisterView(classRef: Function): void {\n\t\tthis.viewSet.add(classRef);\n\t}\n\tregisterComponent(classRef: Function): void {\n\t\tthis.componentSet.add(classRef);\n\t}\n\tregisterService(classRef: Function): void {\n\t\tthis.serviceSet.add(classRef);\n\t}\n\tregisterDirective(classRef: Function): void {\n\t\tthis.directiveSet.add(classRef);\n\t}\n\tregisterPipe(classRef: Function): void {\n\t\tthis.pipeSet.add(classRef);\n\t}\n\n\thasComponent<T>(selector: string): boolean {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\tgetComponentRef<T>(selector: string): ComponentRef<T> | undefined {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn componentRef;\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tgetComponent<T>(selector: string) {\n\t\tfor (const modelClass of this.componentSet) {\n\t\t\tconst componentRef: ComponentRef<T> = Components.getComponentRef(modelClass);\n\t\t\tif (componentRef.selector === selector) {\n\t\t\t\treturn modelClass;\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tgetComponentView(selector: string) {\n\t\treturn this.getComponentRef(selector)?.viewClass;\n\t}\n\n\thasOutput<T>(model: Object, eventName: string): PropertyRef | false {\n\t\tif (Reflect.has(model, 'bootstrap')) {\n\t\t\tconst componentRef: ComponentRef<T> = Reflect.get(model, 'bootstrap');\n\t\t\tif (componentRef.outputs) {\n\t\t\t\tfor (const out of componentRef.outputs) {\n\t\t\t\t\tif (out.viewAttribute === eventName) {\n\t\t\t\t\t\treturn out;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\thasInput<T>(model: Object, eventName: string): PropertyRef | false {\n\t\tif (Reflect.has(model, 'bootstrap')) {\n\t\t\tconst componentRef: ComponentRef<T> = Reflect.get(model, 'bootstrap');\n\t\t\tif (componentRef.inputs) {\n\t\t\t\tfor (const input of componentRef.inputs) {\n\t\t\t\t\tif (input.viewAttribute === eventName) {\n\t\t\t\t\t\treturn input;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\thasDirective<T>(selector: string): boolean {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif (directiveRef.selector === selector) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tdirectiveHasInput<T>(input: string, directiveType: 'attributes' | 'structural' = 'attributes'): boolean {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif ((directiveType === 'attributes' && !directiveRef.selector.startsWith('*'))\n\t\t\t\t|| (directiveType === 'structural' && directiveRef.selector.startsWith('*'))) {\n\t\t\t\tif (directiveRef.inputs?.filter(ref => ref.viewAttribute === input).length > 0) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\tgetDirectiveRef<T>(selector: string): DirectiveRef<T> | undefined {\n\t\tfor (const directiveClass of this.directiveSet) {\n\t\t\tconst directiveRef: DirectiveRef<T> = Components.getBootstrap(directiveClass.prototype);\n\t\t\tif (directiveRef.selector === selector) {\n\t\t\t\treturn directiveRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\n\tgetPipe<T>(pipeName: string): PipeRef<T> | undefined {\n\t\tfor (const pipeClass of this.pipeSet) {\n\t\t\tconst pipeRef: PipeRef<T> = Components.getBootstrap(pipeClass.prototype);\n\t\t\tif (pipeRef.name === pipeName) {\n\t\t\t\treturn pipeRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tgetService<T>(serviceName: string): ServiceRef<T> | undefined {\n\t\tfor (const serviceClass of this.serviceSet) {\n\t\t\tconst serviceRef: ServiceRef<T> = Components.getBootstrap(serviceClass.prototype);\n\t\t\tif (serviceRef.name === serviceName) {\n\t\t\t\treturn serviceRef;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n}\n\nexport const ClassRegistryProvider = new ClassRegistry();\n"]}
@@ -0,0 +1,26 @@
1
+ import { ReactiveScope } from '@ibyar/expressions';
2
+ import { ListenerRef } from '../component/component.js';
3
+ import { HTMLComponent } from '../component/custom-element.js';
4
+ import { RenderHandler } from './render-handler.js';
5
+ declare type ElementScope = {
6
+ [element: string]: HTMLElement;
7
+ };
8
+ export declare class HostListenerHandler implements RenderHandler {
9
+ private listenerRef;
10
+ private element;
11
+ private elementScope;
12
+ private source;
13
+ private eventName;
14
+ private argumentsExpression;
15
+ private stack;
16
+ private scopeSubscription?;
17
+ private listener;
18
+ constructor(listenerRef: ListenerRef, element: HTMLComponent<any>, elementScope: ReactiveScope<ElementScope>);
19
+ onInit(): void;
20
+ private addEventListener;
21
+ private removeEventListener;
22
+ onConnect(): void;
23
+ onDisconnect(): void;
24
+ onDestroy(): void;
25
+ }
26
+ export {};
@@ -0,0 +1,69 @@
1
+ import { JavaScriptParser, Stack } from '@ibyar/expressions';
2
+ export class HostListenerHandler {
3
+ constructor(listenerRef, element, elementScope) {
4
+ this.listenerRef = listenerRef;
5
+ this.element = element;
6
+ this.elementScope = elementScope;
7
+ this.listener = (event) => {
8
+ const method = this.element._proxyModel[this.listenerRef.modelCallbackName];
9
+ if (typeof method === 'function') {
10
+ const eventScope = this.stack.pushBlockScopeFor({ $event: event });
11
+ const params = this.argumentsExpression.get(this.stack);
12
+ this.stack.clearTo(eventScope);
13
+ method.apply(this.element._proxyModel, params);
14
+ typeof event.preventDefault === 'function' && event.preventDefault();
15
+ }
16
+ };
17
+ this.stack = new Stack(elementScope);
18
+ }
19
+ onInit() {
20
+ const args = this.listenerRef.args ?? [];
21
+ const array = `[${args.join(', ')}]`;
22
+ this.argumentsExpression = JavaScriptParser.parse(array);
23
+ if (this.listenerRef.eventName.includes(':')) {
24
+ const [eventSource, eventName] = this.listenerRef.eventName.split(':', 2);
25
+ this.eventName = eventName;
26
+ if ('window' === eventSource.toLowerCase()) {
27
+ this.source = window;
28
+ }
29
+ else {
30
+ let source = this.elementScope.get(eventSource);
31
+ this.scopeSubscription = this.elementScope.subscribe(eventSource, (newValue) => {
32
+ if (source !== newValue) {
33
+ if (source) {
34
+ this.removeEventListener();
35
+ }
36
+ }
37
+ else if (!newValue) {
38
+ this.removeEventListener();
39
+ }
40
+ source = newValue;
41
+ this.addEventListener();
42
+ });
43
+ this.source = source;
44
+ }
45
+ }
46
+ else {
47
+ this.eventName = this.listenerRef.eventName;
48
+ this.source = this.element;
49
+ }
50
+ this.addEventListener();
51
+ }
52
+ addEventListener() {
53
+ this.source?.addEventListener(this.eventName, this.listener);
54
+ }
55
+ removeEventListener() {
56
+ this.source?.removeEventListener(this.eventName, this.listener);
57
+ }
58
+ onConnect() {
59
+ this.scopeSubscription?.resume();
60
+ }
61
+ onDisconnect() {
62
+ this.scopeSubscription?.pause();
63
+ }
64
+ onDestroy() {
65
+ this.scopeSubscription?.unsubscribe();
66
+ this.removeEventListener();
67
+ }
68
+ }
69
+ //# sourceMappingURL=host-listener.handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-listener.handler.js","sourceRoot":"","sources":["../../../src/core/render/host-listener.handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,gBAAgB,EAAoC,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAwBhH,MAAM,OAAO,mBAAmB;IAsB/B,YAAoB,WAAwB,EAAU,OAA2B,EAAU,YAAyC;QAAhH,gBAAW,GAAX,WAAW,CAAa;QAAU,YAAO,GAAP,OAAO,CAAoB;QAAU,iBAAY,GAAZ,YAAY,CAA6B;QAX5H,aAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;YACnC,MAAM,MAAM,GAAyB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,CA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ription, Stack } from '@ibyar/expressions';\nimport { ListenerRef } from '../component/component.js';\nimport { HTMLComponent } from '../component/custom-element.js';\nimport { RenderHandler } from './render-handler.js';\n\ntype ElementScope = { [element: string]: HTMLElement };\n\n/**\n * ```ts\n * class View {\n * \n *\t@HostListener('window:load', ['$event.target', '\"load\"'])\n * \t@HostListener('click', ['$event.target', '\"click\"'])\n * \tpublic onClick(target: any, type: string){\n * \t\tconsole.log(target, type);\n * \t}\n * }\n * ```\n * \n * window.addEventListener('load', $event => listener($event.target, 'load'));\n * \n * view.addEventListener('click', $event => listener($event.target, 'click'));\n * \n */\nexport class HostListenerHandler implements RenderHandler {\n\n\tprivate source: HTMLElement | Window;\n\tprivate eventName: string;\n\n\tprivate argumentsExpression: ArrayExpression;\n\tprivate stack: Stack;\n\n\tprivate scopeSubscription?: ScopeSubscription<ElementScope>;\n\n\n\tprivate listener = (event: Event) => {\n\t\tconst method: Function | undefined = this.element._proxyModel[this.listenerRef.modelCallbackName];\n\t\tif (typeof method === 'function') {\n\t\t\tconst eventScope = this.stack.pushBlockScopeFor({ $event: event });\n\t\t\tconst params = this.argumentsExpression.get(this.stack);\n\t\t\tthis.stack.clearTo(eventScope);\n\t\t\tmethod.apply(this.element._proxyModel, params);\n\t\t\ttypeof event.preventDefault === 'function' && event.preventDefault();\n\t\t}\n\t};\n\n\tconstructor(private listenerRef: ListenerRef, private element: HTMLComponent<any>, private elementScope: ReactiveScope<ElementScope>) {\n\t\tthis.stack = new Stack(elementScope);\n\t}\n\tonInit(): void {\n\t\tconst args = this.listenerRef.args ?? [];\n\t\tconst array = `[${args.join(', ')}]`;\n\t\tthis.argumentsExpression = JavaScriptParser.parse(array) as ArrayExpression;\n\t\tif (this.listenerRef.eventName.includes(':')) {\n\t\t\tconst [eventSource, eventName] = this.listenerRef.eventName.split(':', 2);\n\t\t\tthis.eventName = eventName;\n\t\t\tif ('window' === eventSource.toLowerCase()) {\n\t\t\t\tthis.source = window;\n\t\t\t} else {\n\t\t\t\tlet source = this.elementScope.get(eventSource) as HTMLElement;\n\t\t\t\tthis.scopeSubscription = this.elementScope.subscribe(eventSource, (newValue: HTMLElement) => {\n\t\t\t\t\tif (source !== newValue) {\n\t\t\t\t\t\tif (source) {\n\t\t\t\t\t\t\tthis.removeEventListener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!newValue) {\n\t\t\t\t\t\tthis.removeEventListener();\n\t\t\t\t\t}\n\t\t\t\t\tsource = newValue;\n\t\t\t\t\tthis.addEventListener();\n\t\t\t\t});\n\t\t\t\tthis.source = source;\n\t\t\t}\n\t\t} else {\n\t\t\tthis.eventName = this.listenerRef.eventName;\n\t\t\tthis.source = this.element;\n\t\t}\n\t\tthis.addEventListener();\n\t}\n\n\tprivate addEventListener() {\n\t\tthis.source?.addEventListener(this.eventName, this.listener);\n\t}\n\n\tprivate removeEventListener() {\n\t\tthis.source?.removeEventListener(this.eventName, this.listener);\n\t}\n\n\tonConnect() {\n\t\tthis.scopeSubscription?.resume();\n\t}\n\n\tonDisconnect() {\n\t\tthis.scopeSubscription?.pause();\n\t}\n\n\tonDestroy(): void {\n\t\tthis.scopeSubscription?.unsubscribe();\n\t\tthis.removeEventListener();\n\t}\n\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { OnDestroy, OnInit } from '../component/lifecycle.js';
2
+ export interface RenderHandler extends Partial<OnInit>, Partial<OnDestroy> {
3
+ onConnect?(): void;
4
+ onDisconnect?(): void;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=render-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-handler.js","sourceRoot":"","sources":["../../../src/core/render/render-handler.ts"],"names":[],"mappings":"","sourcesContent":["import { OnDestroy, OnInit } from '../component/lifecycle.js';\n\nexport interface RenderHandler extends Partial<OnInit>, Partial<OnDestroy> {\n\n\t/**\n\t * execute when element attached to parent from ui\n\t */\n\tonConnect?(): void;\n\n\t/**\n\t * execute when element disconnected from ui\n\t */\n\tonDisconnect?(): void;\n\n}\n"]}
package/view/base-view.js CHANGED
@@ -3,14 +3,6 @@ import { isAfterContentChecked, isAfterContentInit, isAfterViewChecked, isAfterV
3
3
  import { ComponentRender } from './render.js';
4
4
  import { ElementModelReactiveScope } from '../component/provider.js';
5
5
  const FACTORY_CACHE = new WeakMap();
6
- function defineInstancePropertyMap(instance, names) {
7
- if (typeof instance !== 'object') {
8
- return;
9
- }
10
- names
11
- .filter(key => !Reflect.has(instance, key))
12
- .forEach(key => Reflect.set(instance, key, undefined));
13
- }
14
6
  export function baseFactoryView(htmlElementType) {
15
7
  if (FACTORY_CACHE.has(htmlElementType)) {
16
8
  return FACTORY_CACHE.get(htmlElementType);
@@ -18,6 +10,7 @@ export function baseFactoryView(htmlElementType) {
18
10
  class CustomView extends htmlElementType {
19
11
  constructor(componentRef, modelClass) {
20
12
  super();
13
+ this.subscriptions = [];
21
14
  this.doBlockCallback = () => {
22
15
  if (isDoCheck(this._model)) {
23
16
  this._model.doCheck.call(this._proxyModel);
@@ -31,16 +24,11 @@ export function baseFactoryView(htmlElementType) {
31
24
  });
32
25
  }
33
26
  const model = new modelClass();
34
- const modelNames = componentRef.inputs.map(input => input.modelProperty)
35
- .concat(componentRef.outputs.map(output => output.modelProperty))
36
- .concat(componentRef.hostBindings.map(host => host.hostPropertyName))
37
- .concat(componentRef.viewChild.map(child => child.modelName));
38
- defineInstancePropertyMap(model, modelNames);
39
27
  this._model = model;
40
- const modelScope = ElementModelReactiveScope.blockScopeFor(model);
28
+ const modelScope = ElementModelReactiveScope.for(model);
41
29
  this._proxyModel = modelScope.getContextProxy();
42
30
  this._modelScope = modelScope;
43
- this._viewScope = ReactiveScope.blockScopeFor({ 'this': this });
31
+ this._viewScope = ReactiveScope.for({ 'this': this });
44
32
  const elementScope = this._viewScope.getScopeOrCreat('this');
45
33
  componentRef.inputs.forEach(input => {
46
34
  elementScope.subscribe(input.viewAttribute, (newValue, oldValue) => {
@@ -59,7 +47,7 @@ export function baseFactoryView(htmlElementType) {
59
47
  if (this._componentRef.view) {
60
48
  Reflect.set(this._model, this._componentRef.view, this);
61
49
  }
62
- this._render = new ComponentRender(this);
50
+ this._render = new ComponentRender(this, this.subscriptions);
63
51
  }
64
52
  getComponentRef() {
65
53
  return this._componentRef;
@@ -120,6 +108,7 @@ export function baseFactoryView(htmlElementType) {
120
108
  if (outputRef) {
121
109
  return this._model[outputRef.modelProperty];
122
110
  }
111
+ return;
123
112
  }
124
113
  hasProp(propName) {
125
114
  return Reflect.has(this._model, propName);
@@ -151,15 +140,16 @@ export function baseFactoryView(htmlElementType) {
151
140
  if (newValue === oldValue) {
152
141
  return;
153
142
  }
154
- const inputRef = this.getInput(name);
155
- if (inputRef) {
156
- }
157
143
  if (isOnChanges(this._model)) {
158
144
  this._model.onChanges.call(this._proxyModel);
159
145
  }
160
146
  this.doBlockCallback();
161
147
  }
162
148
  connectedCallback() {
149
+ if (this.subscriptions.length) {
150
+ this.subscriptions.forEach(sub => sub.unsubscribe());
151
+ }
152
+ this.subscriptions.splice(0, this.subscriptions.length);
163
153
  this._componentRef.inputs.forEach(input => {
164
154
  const inputDefaultValue = this._model[input.modelProperty];
165
155
  if (inputDefaultValue !== null && inputDefaultValue !== undefined) {
@@ -248,6 +238,8 @@ export function baseFactoryView(htmlElementType) {
248
238
  if (isOnDestroy(this._model)) {
249
239
  this._model.onDestroy.call(this._proxyModel);
250
240
  }
241
+ this.subscriptions.forEach(sub => sub.unsubscribe());
242
+ this.subscriptions.splice(0, this.subscriptions.length);
251
243
  }
252
244
  addEventListener(eventName, listener, options) {
253
245
  if ('on' + eventName in this) {
@@ -262,9 +254,6 @@ export function baseFactoryView(htmlElementType) {
262
254
  listener(data);
263
255
  });
264
256
  }
265
- else {
266
- this._model.subscribeModel(eventName, listener);
267
- }
268
257
  }
269
258
  triggerOutput(eventName, value) {
270
259
  const modelEvent = this.getEventEmitter(eventName);