@ibyar/core 0.5.0 → 0.5.1

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.
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<{
@@ -15,17 +20,19 @@ export declare class PipeProvider extends ReadOnlyScope<{
15
20
  get(pipeName: string): any;
16
21
  }
17
22
  export declare class AsyncPipeProvider extends ReadOnlyScope<object> {
18
- static AsyncPipeContext: any;
19
23
  constructor();
20
24
  has(pipeName: string): boolean;
21
- get(pipeName: string): PipeTransform<any, any> | undefined;
25
+ get(pipeName: string): TypeOf<AsyncPipeTransform<any, any>> | undefined;
22
26
  }
23
27
  export declare class AsyncPipeScope<T extends {
24
28
  [key: string]: AsyncPipeTransform<any, any>;
25
- }> extends ReactiveScope<T> {
29
+ }> extends ReactiveScopeControl<T> {
30
+ static blockScope<P extends {
31
+ [key: string]: AsyncPipeTransform<any, any>;
32
+ }>(): AsyncPipeScope<P>;
26
33
  private wrapper;
27
34
  constructor();
28
- set(propertyKey: keyof T, newValue: any, receiver?: any): boolean;
35
+ set(propertyKey: keyof T, pipeClass: TypeOf<AsyncPipeTransform<any, any>>, receiver?: any): boolean;
29
36
  get(propertyKey: keyof T): any;
30
37
  unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
31
38
  }
package/pipe/pipe.js CHANGED
@@ -1,5 +1,11 @@
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
  }
@@ -31,7 +37,7 @@ export class PipeProvider extends ReadOnlyScope {
31
37
  }
32
38
  export class AsyncPipeProvider extends ReadOnlyScope {
33
39
  constructor() {
34
- super(AsyncPipeProvider.AsyncPipeContext, 'block');
40
+ super({}, 'block');
35
41
  }
36
42
  has(pipeName) {
37
43
  const pipeRef = ClassRegistryProvider.getPipe(pipeName);
@@ -40,24 +46,23 @@ export class AsyncPipeProvider extends ReadOnlyScope {
40
46
  get(pipeName) {
41
47
  const pipeRef = ClassRegistryProvider.getPipe(pipeName);
42
48
  if (pipeRef?.asynchronous) {
43
- return new pipeRef.modelClass();
49
+ return pipeRef.modelClass;
44
50
  }
45
- return void 0;
46
51
  }
47
52
  }
48
- AsyncPipeProvider.AsyncPipeContext = Object.create(null);
49
- export class AsyncPipeScope extends ReactiveScope {
53
+ export class AsyncPipeScope extends ReactiveScopeControl {
50
54
  constructor() {
51
55
  super({}, 'block');
52
56
  this.wrapper = {};
53
57
  }
54
- set(propertyKey, newValue, receiver) {
55
- const result = super.set(propertyKey, newValue, receiver);
58
+ static blockScope() {
59
+ return new AsyncPipeScope();
60
+ }
61
+ set(propertyKey, pipeClass, receiver) {
62
+ const detector = createChangeDetectorRef(this, propertyKey);
63
+ const pipe = new pipeClass(detector);
64
+ const result = super.set(propertyKey, pipe, receiver);
56
65
  if (result) {
57
- const pipe = this.context[propertyKey];
58
- pipe.subscribe(value => {
59
- this.emit(propertyKey, value);
60
- });
61
66
  this.wrapper[propertyKey] = (value, ...args) => {
62
67
  return pipe.transform(value, ...args);
63
68
  };
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,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,aAA+C;IAChF;QACC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC;IACD,GAAG,CAAC,QAAgB;QACnB,IAAI,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE;YAC7B,OAAO,IAAI,CAAC;SACZ;QACD,MAAM,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAA0B,QAAQ,CAAC,CAAC;QACjF,OAAO,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;IACvD,CAAC;IACD,GAAG,CAAC,QAAgB;QACnB,IAAI,aAAmC,CAAC;QACxC,IAAI,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC3C,OAAO,aAAa,CAAC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GAAG,CAAC,WAAoB,EAAE,QAAa,EAAE,QAAc;QAC/D,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC1D,IAAI,MAAM,EAAE;YACX,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACvC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;gBACtB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;YACH,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,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":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAqB,MAAM,oBAAoB,CAAC;AAE5F,OAAO,EAAqB,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAcjE,MAAM,OAAgB,kBAAkB;IACvC,YAAsB,iBAAoC;QAApC,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAI,CAAC;CAG/D;AAED,MAAM,UAAU,eAAe,CAA+B,IAAS;IACtE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,aAA+C;IAChF;QACC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpB,CAAC;IACD,GAAG,CAAC,QAAgB;QACn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';\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({}, '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\tconstructor() {\n\t\tsuper({}, 'block');\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}\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, 'block');\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\tthis.unsubscribe(propertyKey, subscription);\n\t\tconst pipe = this.context[propertyKey];\n\t\tpipe.onDestroy();\n\t}\n}\n"]}
package/view/base-view.js CHANGED
@@ -18,6 +18,7 @@ export function baseFactoryView(htmlElementType) {
18
18
  class CustomView extends htmlElementType {
19
19
  constructor(componentRef, modelClass) {
20
20
  super();
21
+ this.subscriptions = [];
21
22
  this.doBlockCallback = () => {
22
23
  if (isDoCheck(this._model)) {
23
24
  this._model.doCheck.call(this._proxyModel);
@@ -59,7 +60,7 @@ export function baseFactoryView(htmlElementType) {
59
60
  if (this._componentRef.view) {
60
61
  Reflect.set(this._model, this._componentRef.view, this);
61
62
  }
62
- this._render = new ComponentRender(this);
63
+ this._render = new ComponentRender(this, this.subscriptions);
63
64
  }
64
65
  getComponentRef() {
65
66
  return this._componentRef;
@@ -160,6 +161,10 @@ export function baseFactoryView(htmlElementType) {
160
161
  this.doBlockCallback();
161
162
  }
162
163
  connectedCallback() {
164
+ if (this.subscriptions.length) {
165
+ this.subscriptions.forEach(sub => sub.unsubscribe());
166
+ }
167
+ this.subscriptions.splice(0, this.subscriptions.length);
163
168
  this._componentRef.inputs.forEach(input => {
164
169
  const inputDefaultValue = this._model[input.modelProperty];
165
170
  if (inputDefaultValue !== null && inputDefaultValue !== undefined) {
@@ -248,6 +253,8 @@ export function baseFactoryView(htmlElementType) {
248
253
  if (isOnDestroy(this._model)) {
249
254
  this._model.onDestroy.call(this._proxyModel);
250
255
  }
256
+ this.subscriptions.forEach(sub => sub.unsubscribe());
257
+ this.subscriptions.splice(0, this.subscriptions.length);
251
258
  }
252
259
  addEventListener(eventName, listener, options) {
253
260
  if ('on' + eventName in this) {
@@ -1 +1 @@
1
- {"version":3,"file":"base-view.js","sourceRoot":"","sources":["../../../src/core/view/base-view.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACN,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAC7D,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAC9D,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,MAAM,aAAa,GAAG,IAAI,OAAO,EAAmD,CAAC;AAErF,SAAS,yBAAyB,CAAmC,QAAW,EAAE,KAAe;IA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AC,eAAe,CAAM,SAAS,CAAC,CAAC;YACzD,IAAI,WAAW,EAAE;gBAEhB,WAAW,CAAC,SAAS,CAAC,CAAC,IAAS,EAAE,EAAE;oBAClC,QAAqB,CAAC,IAAI,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;aACH;iBACI;gBACJ,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,QAAsB,CAAC,CAAC;aAC9D;QACF,CAAC;QAED,aAAa,CAAC,SAAiB,EAAE,KAAW;YAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAM,SAAS,CAAC,CAAC;YACxD,IAAI,UAAU,EAAE;gBACf,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,OAAO;aACP;QACF,CAAC;KACD;IAAA,CAAC;IACF,aAAa,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC/C,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { ReactiveScope } from '@ibyar/expressions';\nimport {\n\tisAfterContentChecked, isAfterContentInit, isAfterViewChecked,\n\tisAfterViewInit, isDoCheck, isOnChanges, isOnDestroy, isOnInit\n} from '../component/lifecycle.js';\nimport { ComponentRef, PropertyRef } from '../component/component.js';\nimport { BaseComponent, CustomElement, HTMLComponent, ModelType } from '../component/custom-element.js';\nimport { EventEmitter } from '../component/events.js';\nimport { ComponentRender } from './render.js';\nimport { ElementModelReactiveScope } from '../component/provider.js';\n\nconst FACTORY_CACHE = new WeakMap<TypeOf<HTMLElement>, TypeOf<HTMLComponent<any>>>();\n\nfunction defineInstancePropertyMap<T extends { [key: string]: any }>(instance: T, names: string[]) {\n\tif (typeof instance !== 'object') {\n\t\treturn;\n\t}\n\tnames\n\t\t.filter(key => !Reflect.has(instance, key))\n\t\t.forEach(key => Reflect.set(instance, key, undefined));\n}\n\nexport function baseFactoryView<T extends object>(htmlElementType: TypeOf<HTMLElement>): TypeOf<HTMLComponent<T>> {\n\n\tif (FACTORY_CACHE.has(htmlElementType)) {\n\t\treturn FACTORY_CACHE.get(htmlElementType) as TypeOf<HTMLComponent<T>>;\n\t}\n\tclass CustomView extends htmlElementType implements BaseComponent<T>, CustomElement {\n\t\t_model: ModelType<T>;\n\t\t_proxyModel: T;\n\t\t_parentComponent: HTMLComponent<object>;\n\t\t_render: ComponentRender<T>;\n\t\t_shadowRoot: ShadowRoot;\n\n\t\t_componentRef: ComponentRef<T>;\n\n\t\t_modelScope: ReactiveScope<T>;\n\t\t_viewScope: ReactiveScope<{ 'this': BaseComponent<T> }>;\n\n\t\tconstructor(componentRef: ComponentRef<T>, modelClass: TypeOf<T>) {\n\t\t\tsuper();\n\t\t\tthis._componentRef = componentRef;\n\t\t\tif (componentRef.isShadowDom) {\n\t\t\t\tthis._shadowRoot = this.attachShadow({\n\t\t\t\t\tmode: componentRef.shadowDomMode,\n\t\t\t\t\tdelegatesFocus: componentRef.shadowDomDelegatesFocus\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst model = new modelClass(/* resolve dependency injection*/);\n\t\t\tconst modelNames = componentRef.inputs.map(input => input.modelProperty)\n\t\t\t\t.concat(componentRef.outputs.map(output => output.modelProperty))\n\t\t\t\t.concat(componentRef.hostBindings.map(host => host.hostPropertyName))\n\t\t\t\t.concat(componentRef.viewChild.map(child => child.modelName));\n\t\t\tdefineInstancePropertyMap(model, modelNames);\n\t\t\tthis._model = model;\n\n\t\t\tconst modelScope = ElementModelReactiveScope.blockScopeFor(model);\n\t\t\tthis._proxyModel = modelScope.getContextProxy();\n\t\t\tthis._modelScope = modelScope;\n\n\t\t\tthis._viewScope = ReactiveScope.blockScopeFor<{ 'this': BaseComponent<T> }>({ 'this': this });\n\t\t\tconst elementScope = this._viewScope.getScopeOrCreat('this');\n\t\t\tcomponentRef.inputs.forEach(input => {\n\t\t\t\telementScope.subscribe(input.viewAttribute as any, (newValue, oldValue) => {\n\t\t\t\t\tif (newValue === oldValue) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis._modelScope.set(input.modelProperty as any, newValue);\n\t\t\t\t});\n\t\t\t\tthis._modelScope.subscribe(input.modelProperty as any, (newValue, oldValue) => {\n\t\t\t\t\tif (newValue === oldValue) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\telementScope.emit(input.viewAttribute as any, newValue, oldValue);\n\t\t\t\t});\n\t\t\t});\n\n\n\t\t\t// if property of the model has view decorator\n\t\t\tif (this._componentRef.view) {\n\t\t\t\tReflect.set(this._model, this._componentRef.view, this);\n\t\t\t}\n\t\t\tthis._render = new ComponentRender(this);\n\t\t}\n\n\t\tdoBlockCallback = (): void => {\n\t\t\tif (isDoCheck(this._model)) {\n\t\t\t\tthis._model.doCheck.call(this._proxyModel);\n\t\t\t}\n\t\t};\n\n\t\tgetComponentRef(): ComponentRef<T> {\n\t\t\treturn this._componentRef;\n\t\t}\n\n\t\tsetParentComponent(parent: HTMLComponent<any>): void {\n\t\t\tthis._parentComponent = parent;\n\t\t}\n\n\t\tgetParentComponent(): HTMLComponent<any> {\n\t\t\treturn this._parentComponent;\n\t\t}\n\n\t\thasParentComponent(): boolean {\n\t\t\treturn this._parentComponent ? true : false;\n\t\t}\n\n\t\thasInputStartWith(viewProp: string): boolean {\n\t\t\tlet dotIndex = viewProp.indexOf('.');\n\t\t\tif (dotIndex > 0) {\n\t\t\t\tviewProp = viewProp.substring(0, dotIndex);\n\t\t\t}\n\t\t\treturn this.hasInput(viewProp);\n\t\t}\n\n\t\tgetInputStartWith(viewProp: string): PropertyRef | undefined {\n\t\t\tlet index = viewProp.indexOf('.');\n\t\t\tif (index > 0) {\n\t\t\t\tviewProp = viewProp.substring(0, index);\n\t\t\t}\n\t\t\tindex = viewProp.indexOf('[');\n\t\t\tif (index > 0) {\n\t\t\t\tviewProp = viewProp.substring(0, index);\n\t\t\t}\n\t\t\treturn this.getInput(viewProp);\n\t\t}\n\n\t\thasInput(viewProp: string): boolean {\n\t\t\treturn this._componentRef.inputs.some(input => input.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetInput(viewProp: string): PropertyRef | undefined {\n\t\t\treturn this._componentRef.inputs.find(input => input.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetInputValue(viewProp: string): any {\n\t\t\tconst inputRef = this.getInput(viewProp);\n\t\t\tif (inputRef) {\n\t\t\t\treturn this._model[inputRef.modelProperty];\n\t\t\t}\n\t\t}\n\n\t\tsetInputValue(viewProp: PropertyKey, value: any): void {\n\t\t\tconst inputRef = this.getInput(viewProp as string);\n\t\t\tif (inputRef) {\n\t\t\t\t// console.log('about to change input', inputRef.modelProperty, value);\n\t\t\t\t// Reflect.set(this._model, inputRef.modelProperty, value);\n\t\t\t\t// this._model.emitChangeModel(inputRef.modelProperty);\n\t\t\t\tthis._modelScope.set(inputRef.modelProperty as never, value);\n\t\t\t}\n\t\t}\n\n\t\thasOutput(viewProp: string): boolean {\n\t\t\treturn this._componentRef.outputs.some(output => output.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetOutput(viewProp: string): PropertyRef | undefined {\n\t\t\treturn this._componentRef.outputs.find(output => output.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetEventEmitter<V>(viewProp: string): EventEmitter<V> | undefined {\n\t\t\tconst outputRef = this.getOutput(viewProp);\n\t\t\tif (outputRef) {\n\t\t\t\treturn this._model[outputRef.modelProperty] as EventEmitter<V>;\n\t\t\t}\n\t\t}\n\n\t\thasProp(propName: string): boolean {\n\t\t\treturn Reflect.has(this._model, propName);\n\t\t}\n\n\t\tprivate setAttributeHelper(attrViewName: string, value: any): void {\n\t\t\tif (value === null || value === undefined) {\n\t\t\t\tthis.removeAttribute(attrViewName);\n\t\t\t}\n\t\t\telse if (typeof value === 'boolean') {\n\t\t\t\tif (value) {\n\t\t\t\t\tsuper.setAttribute(attrViewName, '');\n\t\t\t\t} else {\n\t\t\t\t\tthis.removeAttribute(attrViewName);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsuper.setAttribute(attrViewName, value);\n\t\t\t}\n\t\t}\n\n\t\tsetAttribute(attrViewName: string, value: any): void {\n\t\t\tthis.setInputValue(attrViewName, value);\n\t\t\tthis.setAttributeHelper(attrViewName, value);\n\t\t}\n\n\t\tgetAttribute(attrViewName: string): string | null {\n\t\t\treturn this.getInputValue(attrViewName) ?? super.getAttribute(attrViewName);\n\t\t}\n\n\t\tattributeChangedCallback(name: string, oldValue: string, newValue: string) {\n\t\t\tif (newValue === oldValue) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// this._changeObservable.emit(name);\n\t\t\tconst inputRef = this.getInput(name);\n\t\t\tif (inputRef) {\n\t\t\t\t// this._model.emitChangeModel(inputRef.modelProperty);\n\t\t\t}\n\t\t\tif (isOnChanges(this._model)) {\n\t\t\t\tthis._model.onChanges.call(this._proxyModel);\n\t\t\t}\n\t\t\tthis.doBlockCallback();\n\t\t}\n\n\t\tconnectedCallback() {\n\n\t\t\tthis._componentRef.inputs.forEach(input => {\n\t\t\t\tconst inputDefaultValue = this._model[input.modelProperty];\n\t\t\t\tif (inputDefaultValue !== null && inputDefaultValue !== undefined) {\n\t\t\t\t\tthis.setAttributeHelper(input.viewAttribute, inputDefaultValue);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// if (!this.hasParentComponent() && this.attributes.length > 0) {\n\t\t\t// \tlet oldAttrValues = Array.prototype.slice.call(this.attributes);\n\t\t\t//\toldAttrValues.forEach((attr: Attr) => {\n\t\t\t// \t\tReflect.set(this, attr.name, attr.value);\n\t\t\t// \t});\n\t\t\t// }\n\n\t\t\tif (!this.hasParentComponent() && this.attributes.length > 0) {\n\t\t\t\tlet attrs: Attr[] = Array.prototype.slice.call(this.attributes);\n\t\t\t\tattrs.forEach(attr => this.initOuterAttribute(attr));\n\t\t\t}\n\n\t\t\tif (isOnChanges(this._model)) {\n\t\t\t\tthis._model.onChanges.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isOnInit(this._model)) {\n\t\t\t\tthis._model.onInit.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isDoCheck(this._model)) {\n\t\t\t\tthis._model.doCheck.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isAfterContentInit(this._model)) {\n\t\t\t\tthis._model.afterContentInit.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isAfterContentChecked(this._model)) {\n\t\t\t\tthis._model.afterContentChecked.call(this._proxyModel);\n\t\t\t}\n\n\t\t\t// if (!this.hasParentComponent()) {\n\t\t\t// \tArray.prototype.slice.call(this.attributes).forEach((attr: Attr) => {\n\t\t\t// \t\tthis.initOuterAttribute(attr);\n\t\t\t// \t});\n\t\t\t// }\n\n\t\t\t// do once\n\t\t\tif (this.childNodes.length === 0) {\n\t\t\t\t// setup ui view\n\t\t\t\tthis._render.initView();\n\n\t\t\t\t// init Host Listener events\n\t\t\t\tthis._render.initHostListener();\n\t\t\t}\n\n\t\t\tif (isAfterViewInit(this._model)) {\n\t\t\t\tthis._model.afterViewInit.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isAfterViewChecked(this._model)) {\n\t\t\t\tthis._model.afterViewChecked.call(this._proxyModel);\n\t\t\t}\n\t\t\tthis.doBlockCallback = () => {\n\t\t\t\tif (isDoCheck(this._model)) {\n\t\t\t\t\tthis._model.doCheck.call(this._proxyModel);\n\t\t\t\t}\n\t\t\t\tif (isAfterContentChecked(this._model)) {\n\t\t\t\t\tthis._model.afterContentChecked.call(this._proxyModel);\n\t\t\t\t}\n\t\t\t\tif (isAfterViewChecked(this._model)) {\n\t\t\t\t\tthis._model.afterViewChecked.call(this._proxyModel);\n\t\t\t\t}\n\t\t\t\t// this.emitRootChanges();\n\t\t\t};\n\t\t\t// this.emitRootChanges();\n\t\t}\n\n\t\t// emitRootChanges(): void {\n\t\t// \tthis.emitChanges(...Object.keys(this._model.__observable).filter(event => event !== 'destroy'));\n\t\t// }\n\n\t\t// emitChanges(...events: string[]): void {\n\t\t// \tconst sources: any[] = [];\n\t\t// \tevents.forEach(key => {\n\t\t// \t\tthis._model.emitChangeModel(key, sources);\n\t\t// \t});\n\t\t// }\n\n\t\tinitOuterAttribute(attr: Attr) {\n\t\t\t// [window, this] scop\n\t\t\tlet elementAttr = attr.name;\n\t\t\tlet modelProperty = attr.value;\n\t\t\tif (elementAttr.startsWith('[')) {\n\t\t\t\telementAttr = elementAttr.substring(1, elementAttr.length - 1);\n\t\t\t\tif (Reflect.has(window, modelProperty)) {\n\t\t\t\t\tthis.setInputValue(elementAttr, Reflect.get(window, modelProperty));\n\t\t\t\t}\n\t\t\t\t// else {\n\t\t\t\t// \tlet value: any;\n\t\t\t\t// \tObject.defineProperty(window, modelProperty, {\n\t\t\t\t// \t\tset: (v: any) => {\n\t\t\t\t// \t\t\tvalue = v;\n\t\t\t\t// \t\t\tif (this) {\n\t\t\t\t// \t\t\t\tthis.setInputValue(elementAttr, v);\n\t\t\t\t// \t\t\t\t// fake connect element\n\t\t\t\t// \t\t\t\tthis.connectedCallback();\n\t\t\t\t// \t\t\t}\n\t\t\t\t// \t\t},\n\t\t\t\t// \t\tget: (): any => value\n\t\t\t\t// \t});\n\t\t\t\t// }\n\n\t\t\t}\n\t\t\telse if (elementAttr.startsWith('(')) {\n\t\t\t\t// (elementAttr)=\"modelProperty()\"\n\t\t\t\telementAttr = elementAttr.substring(1, elementAttr.length - 1);\n\t\t\t\t// this.handleEvent(element, elementAttr, viewProperty);\n\t\t\t\tmodelProperty = modelProperty.endsWith('()') ?\n\t\t\t\t\tmodelProperty.substring(0, modelProperty.length - 2) : modelProperty;\n\t\t\t\tlet callback: Function = Reflect.get(window, modelProperty);\n\t\t\t\tthis.addEventListener(elementAttr, event => {\n\t\t\t\t\tcallback(event);\n\t\t\t\t});\n\t\t\t} else if (elementAttr.startsWith('on')) {\n\t\t\t\tconst modelEvent = this.getEventEmitter<any>(elementAttr.substring(2));\n\t\t\t\tif (modelEvent) {\n\t\t\t\t\t// modelEvent.subscribe(listener);\n\t\t\t\t\tmodelProperty = modelProperty.endsWith('()') ?\n\t\t\t\t\t\tmodelProperty.substring(0, modelProperty.length - 2) : modelProperty;\n\t\t\t\t\tlet listener: Function = Reflect.get(window, modelProperty);\n\t\t\t\t\tmodelEvent.subscribe((data: any) => {\n\t\t\t\t\t\t(listener as Function)(data);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.setInputValue(attr.name, attr.value);\n\t\t\t}\n\t\t}\n\n\t\tadoptedCallback() {\n\t\t\t// restart the process\n\t\t\tthis.innerHTML = '';\n\t\t\tthis.connectedCallback();\n\t\t}\n\t\tdisconnectedCallback() {\n\t\t\t// notify first, then call model.onDestroy func\n\t\t\t// this._changeObservable.emit('destroy');\n\t\t\tif (isOnDestroy(this._model)) {\n\t\t\t\tthis._model.onDestroy.call(this._proxyModel);\n\t\t\t}\n\t\t\t// this.emitChanges('destroy');\n\t\t}\n\n\t\t// events api\n\t\taddEventListener(eventName: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void {\n\t\t\tif ('on' + eventName in this) {\n\t\t\t\tsuper.addEventListener(eventName, (event: Event) => {\n\t\t\t\t\t(listener as Function)(event);\n\t\t\t\t}, options);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst modelOutput = this.getEventEmitter<any>(eventName);\n\t\t\tif (modelOutput) {\n\t\t\t\t// modelOutput.subscribe(listener);\n\t\t\t\tmodelOutput.subscribe((data: any) => {\n\t\t\t\t\t(listener as Function)(data);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._model.subscribeModel(eventName, listener as () => void);\n\t\t\t}\n\t\t}\n\n\t\ttriggerOutput(eventName: string, value?: any): void {\n\t\t\tconst modelEvent = this.getEventEmitter<any>(eventName);\n\t\t\tif (modelEvent) {\n\t\t\t\tmodelEvent.emit(value);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\tFACTORY_CACHE.set(htmlElementType, CustomView);\n\treturn CustomView;\n}\n\n// const CustomViewTypes: WeakMap<TypeOf<HTMLElement>, TypeOf<HTMLComponent<any>>> = new WeakMap();\n// function createViewClass(elementType: TypeOf<HTMLElement>, isForm: boolean) {\n// if (isForm) {\n// let ViewClass = baseFormFactoryView(elementType);\n// CustomViewTypes.set(elementType, ViewClass);\n// return ViewClass;\n// }\n// else {\n// let ViewClass = baseFactoryView(elementType);\n// CustomViewTypes.set(elementType, ViewClass);\n// return ViewClass;\n// }\n// }\n\n// export function getBaseViewClassByHTMLElementType(elementType?: TypeOf<HTMLElement>, isFormAssociated?: boolean) {\n// if (elementType && CustomViewTypes.has(elementType)) {\n// return CustomViewTypes.get(elementType);\n// }\n// // start to created view class\n// else if (!elementType || elementType === HTMLElement) {\n// return createViewClass(HTMLElement, isFormAssociated || false);\n// }\n// if (CustomViewTypes.has(elementType)) {\n// return CustomViewTypes.get(elementType);\n// } else {\n\n// }\n// }\n"]}
1
+ {"version":3,"file":"base-view.js","sourceRoot":"","sources":["../../../src/core/view/base-view.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAmC,MAAM,oBAAoB,CAAC;AACpF,OAAO,EACN,qBAAqB,EAAE,kBAAkB,EAAE,kBAAkB,EAC7D,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAC9D,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAErE,MAAM,aAAa,GAAG,IAAI,OAAO,EAAmD,CAAC;AAErF,SAAS,yBAAyB,CAAmC,QAAW,EAAE,KAAe;IAChG,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QACjC,OAAO;KACP;IACD,KAAK;SACH,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;SAC1C,OAAO,C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AC,CAAC;QACzD,CAAC;QAGD,gBAAgB,CAAC,SAAiB,EAAE,QAAmD,EAAE,OAA2C;YACnI,IAAI,IAAI,GAAG,SAAS,IAAI,IAAI,EAAE;gBAC7B,KAAK,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAAY,EAAE,EAAE;oBACjD,QAAqB,CAAC,KAAK,CAAC,CAAC;gBAC/B,CAAC,EAAE,OAAO,CAAC,CAAC;gBACZ,OAAO;aACP;YACD,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAM,SAAS,CAAC,CAAC;YACzD,IAAI,WAAW,EAAE;gBAEhB,WAAW,CAAC,SAAS,CAAC,CAAC,IAAS,EAAE,EAAE;oBAClC,QAAqB,CAAC,IAAI,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;aACH;iBACI;gBACJ,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,QAAsB,CAAC,CAAC;aAC9D;QACF,CAAC;QAED,aAAa,CAAC,SAAiB,EAAE,KAAW;YAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,CAAM,SAAS,CAAC,CAAC;YACxD,IAAI,UAAU,EAAE;gBACf,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,OAAO;aACP;QACF,CAAC;KACD;IAAA,CAAC;IACF,aAAa,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC/C,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["import type { TypeOf } from '../utils/typeof.js';\nimport { ReactiveScope, ScopeContext, ScopeSubscription } from '@ibyar/expressions';\nimport {\n\tisAfterContentChecked, isAfterContentInit, isAfterViewChecked,\n\tisAfterViewInit, isDoCheck, isOnChanges, isOnDestroy, isOnInit\n} from '../component/lifecycle.js';\nimport { ComponentRef, PropertyRef } from '../component/component.js';\nimport { BaseComponent, CustomElement, HTMLComponent, ModelType } from '../component/custom-element.js';\nimport { EventEmitter } from '../component/events.js';\nimport { ComponentRender } from './render.js';\nimport { ElementModelReactiveScope } from '../component/provider.js';\n\nconst FACTORY_CACHE = new WeakMap<TypeOf<HTMLElement>, TypeOf<HTMLComponent<any>>>();\n\nfunction defineInstancePropertyMap<T extends { [key: string]: any }>(instance: T, names: string[]) {\n\tif (typeof instance !== 'object') {\n\t\treturn;\n\t}\n\tnames\n\t\t.filter(key => !Reflect.has(instance, key))\n\t\t.forEach(key => Reflect.set(instance, key, undefined));\n}\n\nexport function baseFactoryView<T extends object>(htmlElementType: TypeOf<HTMLElement>): TypeOf<HTMLComponent<T>> {\n\n\tif (FACTORY_CACHE.has(htmlElementType)) {\n\t\treturn FACTORY_CACHE.get(htmlElementType) as TypeOf<HTMLComponent<T>>;\n\t}\n\tclass CustomView extends htmlElementType implements BaseComponent<T>, CustomElement {\n\t\t_model: ModelType<T>;\n\t\t_proxyModel: T;\n\t\t_parentComponent: HTMLComponent<object>;\n\t\t_render: ComponentRender<T>;\n\t\t_shadowRoot: ShadowRoot;\n\n\t\t_componentRef: ComponentRef<T>;\n\n\t\t_modelScope: ReactiveScope<T>;\n\t\t_viewScope: ReactiveScope<{ 'this': BaseComponent<T> }>;\n\n\t\tprivate subscriptions: ScopeSubscription<ScopeContext>[] = [];\n\n\t\tconstructor(componentRef: ComponentRef<T>, modelClass: TypeOf<T>) {\n\t\t\tsuper();\n\t\t\tthis._componentRef = componentRef;\n\t\t\tif (componentRef.isShadowDom) {\n\t\t\t\tthis._shadowRoot = this.attachShadow({\n\t\t\t\t\tmode: componentRef.shadowDomMode,\n\t\t\t\t\tdelegatesFocus: componentRef.shadowDomDelegatesFocus\n\t\t\t\t});\n\t\t\t}\n\t\t\tconst model = new modelClass(/* resolve dependency injection*/);\n\t\t\tconst modelNames = componentRef.inputs.map(input => input.modelProperty)\n\t\t\t\t.concat(componentRef.outputs.map(output => output.modelProperty))\n\t\t\t\t.concat(componentRef.hostBindings.map(host => host.hostPropertyName))\n\t\t\t\t.concat(componentRef.viewChild.map(child => child.modelName));\n\t\t\tdefineInstancePropertyMap(model, modelNames);\n\t\t\tthis._model = model;\n\n\t\t\tconst modelScope = ElementModelReactiveScope.blockScopeFor(model);\n\t\t\tthis._proxyModel = modelScope.getContextProxy();\n\t\t\tthis._modelScope = modelScope;\n\n\t\t\tthis._viewScope = ReactiveScope.blockScopeFor<{ 'this': BaseComponent<T> }>({ 'this': this });\n\t\t\tconst elementScope = this._viewScope.getScopeOrCreat('this');\n\t\t\tcomponentRef.inputs.forEach(input => {\n\t\t\t\telementScope.subscribe(input.viewAttribute as any, (newValue, oldValue) => {\n\t\t\t\t\tif (newValue === oldValue) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis._modelScope.set(input.modelProperty as any, newValue);\n\t\t\t\t});\n\t\t\t\tthis._modelScope.subscribe(input.modelProperty as any, (newValue, oldValue) => {\n\t\t\t\t\tif (newValue === oldValue) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\telementScope.emit(input.viewAttribute as any, newValue, oldValue);\n\t\t\t\t});\n\t\t\t});\n\n\n\t\t\t// if property of the model has view decorator\n\t\t\tif (this._componentRef.view) {\n\t\t\t\tReflect.set(this._model, this._componentRef.view, this);\n\t\t\t}\n\t\t\tthis._render = new ComponentRender(this, this.subscriptions);\n\t\t}\n\n\t\tdoBlockCallback = (): void => {\n\t\t\tif (isDoCheck(this._model)) {\n\t\t\t\tthis._model.doCheck.call(this._proxyModel);\n\t\t\t}\n\t\t};\n\n\t\tgetComponentRef(): ComponentRef<T> {\n\t\t\treturn this._componentRef;\n\t\t}\n\n\t\tsetParentComponent(parent: HTMLComponent<any>): void {\n\t\t\tthis._parentComponent = parent;\n\t\t}\n\n\t\tgetParentComponent(): HTMLComponent<any> {\n\t\t\treturn this._parentComponent;\n\t\t}\n\n\t\thasParentComponent(): boolean {\n\t\t\treturn this._parentComponent ? true : false;\n\t\t}\n\n\t\thasInputStartWith(viewProp: string): boolean {\n\t\t\tlet dotIndex = viewProp.indexOf('.');\n\t\t\tif (dotIndex > 0) {\n\t\t\t\tviewProp = viewProp.substring(0, dotIndex);\n\t\t\t}\n\t\t\treturn this.hasInput(viewProp);\n\t\t}\n\n\t\tgetInputStartWith(viewProp: string): PropertyRef | undefined {\n\t\t\tlet index = viewProp.indexOf('.');\n\t\t\tif (index > 0) {\n\t\t\t\tviewProp = viewProp.substring(0, index);\n\t\t\t}\n\t\t\tindex = viewProp.indexOf('[');\n\t\t\tif (index > 0) {\n\t\t\t\tviewProp = viewProp.substring(0, index);\n\t\t\t}\n\t\t\treturn this.getInput(viewProp);\n\t\t}\n\n\t\thasInput(viewProp: string): boolean {\n\t\t\treturn this._componentRef.inputs.some(input => input.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetInput(viewProp: string): PropertyRef | undefined {\n\t\t\treturn this._componentRef.inputs.find(input => input.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetInputValue(viewProp: string): any {\n\t\t\tconst inputRef = this.getInput(viewProp);\n\t\t\tif (inputRef) {\n\t\t\t\treturn this._model[inputRef.modelProperty];\n\t\t\t}\n\t\t}\n\n\t\tsetInputValue(viewProp: PropertyKey, value: any): void {\n\t\t\tconst inputRef = this.getInput(viewProp as string);\n\t\t\tif (inputRef) {\n\t\t\t\t// console.log('about to change input', inputRef.modelProperty, value);\n\t\t\t\t// Reflect.set(this._model, inputRef.modelProperty, value);\n\t\t\t\t// this._model.emitChangeModel(inputRef.modelProperty);\n\t\t\t\tthis._modelScope.set(inputRef.modelProperty as never, value);\n\t\t\t}\n\t\t}\n\n\t\thasOutput(viewProp: string): boolean {\n\t\t\treturn this._componentRef.outputs.some(output => output.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetOutput(viewProp: string): PropertyRef | undefined {\n\t\t\treturn this._componentRef.outputs.find(output => output.viewAttribute === viewProp);\n\t\t}\n\n\t\tgetEventEmitter<V>(viewProp: string): EventEmitter<V> | undefined {\n\t\t\tconst outputRef = this.getOutput(viewProp);\n\t\t\tif (outputRef) {\n\t\t\t\treturn this._model[outputRef.modelProperty] as EventEmitter<V>;\n\t\t\t}\n\t\t}\n\n\t\thasProp(propName: string): boolean {\n\t\t\treturn Reflect.has(this._model, propName);\n\t\t}\n\n\t\tprivate setAttributeHelper(attrViewName: string, value: any): void {\n\t\t\tif (value === null || value === undefined) {\n\t\t\t\tthis.removeAttribute(attrViewName);\n\t\t\t}\n\t\t\telse if (typeof value === 'boolean') {\n\t\t\t\tif (value) {\n\t\t\t\t\tsuper.setAttribute(attrViewName, '');\n\t\t\t\t} else {\n\t\t\t\t\tthis.removeAttribute(attrViewName);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tsuper.setAttribute(attrViewName, value);\n\t\t\t}\n\t\t}\n\n\t\tsetAttribute(attrViewName: string, value: any): void {\n\t\t\tthis.setInputValue(attrViewName, value);\n\t\t\tthis.setAttributeHelper(attrViewName, value);\n\t\t}\n\n\t\tgetAttribute(attrViewName: string): string | null {\n\t\t\treturn this.getInputValue(attrViewName) ?? super.getAttribute(attrViewName);\n\t\t}\n\n\t\tattributeChangedCallback(name: string, oldValue: string, newValue: string) {\n\t\t\tif (newValue === oldValue) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// this._changeObservable.emit(name);\n\t\t\tconst inputRef = this.getInput(name);\n\t\t\tif (inputRef) {\n\t\t\t\t// this._model.emitChangeModel(inputRef.modelProperty);\n\t\t\t}\n\t\t\tif (isOnChanges(this._model)) {\n\t\t\t\tthis._model.onChanges.call(this._proxyModel);\n\t\t\t}\n\t\t\tthis.doBlockCallback();\n\t\t}\n\n\t\tconnectedCallback() {\n\t\t\tif (this.subscriptions.length) {\n\t\t\t\tthis.subscriptions.forEach(sub => sub.unsubscribe());\n\t\t\t}\n\t\t\tthis.subscriptions.splice(0, this.subscriptions.length);\n\t\t\tthis._componentRef.inputs.forEach(input => {\n\t\t\t\tconst inputDefaultValue = this._model[input.modelProperty];\n\t\t\t\tif (inputDefaultValue !== null && inputDefaultValue !== undefined) {\n\t\t\t\t\tthis.setAttributeHelper(input.viewAttribute, inputDefaultValue);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\t// if (!this.hasParentComponent() && this.attributes.length > 0) {\n\t\t\t// \tlet oldAttrValues = Array.prototype.slice.call(this.attributes);\n\t\t\t//\toldAttrValues.forEach((attr: Attr) => {\n\t\t\t// \t\tReflect.set(this, attr.name, attr.value);\n\t\t\t// \t});\n\t\t\t// }\n\n\t\t\tif (!this.hasParentComponent() && this.attributes.length > 0) {\n\t\t\t\tlet attrs: Attr[] = Array.prototype.slice.call(this.attributes);\n\t\t\t\tattrs.forEach(attr => this.initOuterAttribute(attr));\n\t\t\t}\n\n\t\t\tif (isOnChanges(this._model)) {\n\t\t\t\tthis._model.onChanges.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isOnInit(this._model)) {\n\t\t\t\tthis._model.onInit.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isDoCheck(this._model)) {\n\t\t\t\tthis._model.doCheck.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isAfterContentInit(this._model)) {\n\t\t\t\tthis._model.afterContentInit.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isAfterContentChecked(this._model)) {\n\t\t\t\tthis._model.afterContentChecked.call(this._proxyModel);\n\t\t\t}\n\n\t\t\t// if (!this.hasParentComponent()) {\n\t\t\t// \tArray.prototype.slice.call(this.attributes).forEach((attr: Attr) => {\n\t\t\t// \t\tthis.initOuterAttribute(attr);\n\t\t\t// \t});\n\t\t\t// }\n\n\t\t\t// do once\n\t\t\tif (this.childNodes.length === 0) {\n\t\t\t\t// setup ui view\n\t\t\t\tthis._render.initView();\n\n\t\t\t\t// init Host Listener events\n\t\t\t\tthis._render.initHostListener();\n\t\t\t}\n\n\t\t\tif (isAfterViewInit(this._model)) {\n\t\t\t\tthis._model.afterViewInit.call(this._proxyModel);\n\t\t\t}\n\t\t\tif (isAfterViewChecked(this._model)) {\n\t\t\t\tthis._model.afterViewChecked.call(this._proxyModel);\n\t\t\t}\n\t\t\tthis.doBlockCallback = () => {\n\t\t\t\tif (isDoCheck(this._model)) {\n\t\t\t\t\tthis._model.doCheck.call(this._proxyModel);\n\t\t\t\t}\n\t\t\t\tif (isAfterContentChecked(this._model)) {\n\t\t\t\t\tthis._model.afterContentChecked.call(this._proxyModel);\n\t\t\t\t}\n\t\t\t\tif (isAfterViewChecked(this._model)) {\n\t\t\t\t\tthis._model.afterViewChecked.call(this._proxyModel);\n\t\t\t\t}\n\t\t\t\t// this.emitRootChanges();\n\t\t\t};\n\t\t\t// this.emitRootChanges();\n\t\t}\n\n\t\t// emitRootChanges(): void {\n\t\t// \tthis.emitChanges(...Object.keys(this._model.__observable).filter(event => event !== 'destroy'));\n\t\t// }\n\n\t\t// emitChanges(...events: string[]): void {\n\t\t// \tconst sources: any[] = [];\n\t\t// \tevents.forEach(key => {\n\t\t// \t\tthis._model.emitChangeModel(key, sources);\n\t\t// \t});\n\t\t// }\n\n\t\tinitOuterAttribute(attr: Attr) {\n\t\t\t// [window, this] scop\n\t\t\tlet elementAttr = attr.name;\n\t\t\tlet modelProperty = attr.value;\n\t\t\tif (elementAttr.startsWith('[')) {\n\t\t\t\telementAttr = elementAttr.substring(1, elementAttr.length - 1);\n\t\t\t\tif (Reflect.has(window, modelProperty)) {\n\t\t\t\t\tthis.setInputValue(elementAttr, Reflect.get(window, modelProperty));\n\t\t\t\t}\n\t\t\t\t// else {\n\t\t\t\t// \tlet value: any;\n\t\t\t\t// \tObject.defineProperty(window, modelProperty, {\n\t\t\t\t// \t\tset: (v: any) => {\n\t\t\t\t// \t\t\tvalue = v;\n\t\t\t\t// \t\t\tif (this) {\n\t\t\t\t// \t\t\t\tthis.setInputValue(elementAttr, v);\n\t\t\t\t// \t\t\t\t// fake connect element\n\t\t\t\t// \t\t\t\tthis.connectedCallback();\n\t\t\t\t// \t\t\t}\n\t\t\t\t// \t\t},\n\t\t\t\t// \t\tget: (): any => value\n\t\t\t\t// \t});\n\t\t\t\t// }\n\n\t\t\t}\n\t\t\telse if (elementAttr.startsWith('(')) {\n\t\t\t\t// (elementAttr)=\"modelProperty()\"\n\t\t\t\telementAttr = elementAttr.substring(1, elementAttr.length - 1);\n\t\t\t\t// this.handleEvent(element, elementAttr, viewProperty);\n\t\t\t\tmodelProperty = modelProperty.endsWith('()') ?\n\t\t\t\t\tmodelProperty.substring(0, modelProperty.length - 2) : modelProperty;\n\t\t\t\tlet callback: Function = Reflect.get(window, modelProperty);\n\t\t\t\tthis.addEventListener(elementAttr, event => {\n\t\t\t\t\tcallback(event);\n\t\t\t\t});\n\t\t\t} else if (elementAttr.startsWith('on')) {\n\t\t\t\tconst modelEvent = this.getEventEmitter<any>(elementAttr.substring(2));\n\t\t\t\tif (modelEvent) {\n\t\t\t\t\t// modelEvent.subscribe(listener);\n\t\t\t\t\tmodelProperty = modelProperty.endsWith('()') ?\n\t\t\t\t\t\tmodelProperty.substring(0, modelProperty.length - 2) : modelProperty;\n\t\t\t\t\tlet listener: Function = Reflect.get(window, modelProperty);\n\t\t\t\t\tmodelEvent.subscribe((data: any) => {\n\t\t\t\t\t\t(listener as Function)(data);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tthis.setInputValue(attr.name, attr.value);\n\t\t\t}\n\t\t}\n\n\t\tadoptedCallback() {\n\t\t\t// restart the process\n\t\t\tthis.innerHTML = '';\n\t\t\tthis.connectedCallback();\n\t\t}\n\t\tdisconnectedCallback() {\n\t\t\t// notify first, then call model.onDestroy func\n\t\t\tif (isOnDestroy(this._model)) {\n\t\t\t\tthis._model.onDestroy.call(this._proxyModel);\n\t\t\t}\n\t\t\tthis.subscriptions.forEach(sub => sub.unsubscribe());\n\t\t\tthis.subscriptions.splice(0, this.subscriptions.length);\n\t\t}\n\n\t\t// events api\n\t\taddEventListener(eventName: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void {\n\t\t\tif ('on' + eventName in this) {\n\t\t\t\tsuper.addEventListener(eventName, (event: Event) => {\n\t\t\t\t\t(listener as Function)(event);\n\t\t\t\t}, options);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst modelOutput = this.getEventEmitter<any>(eventName);\n\t\t\tif (modelOutput) {\n\t\t\t\t// modelOutput.subscribe(listener);\n\t\t\t\tmodelOutput.subscribe((data: any) => {\n\t\t\t\t\t(listener as Function)(data);\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._model.subscribeModel(eventName, listener as () => void);\n\t\t\t}\n\t\t}\n\n\t\ttriggerOutput(eventName: string, value?: any): void {\n\t\t\tconst modelEvent = this.getEventEmitter<any>(eventName);\n\t\t\tif (modelEvent) {\n\t\t\t\tmodelEvent.emit(value);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\tFACTORY_CACHE.set(htmlElementType, CustomView);\n\treturn CustomView;\n}\n\n// const CustomViewTypes: WeakMap<TypeOf<HTMLElement>, TypeOf<HTMLComponent<any>>> = new WeakMap();\n// function createViewClass(elementType: TypeOf<HTMLElement>, isForm: boolean) {\n// if (isForm) {\n// let ViewClass = baseFormFactoryView(elementType);\n// CustomViewTypes.set(elementType, ViewClass);\n// return ViewClass;\n// }\n// else {\n// let ViewClass = baseFactoryView(elementType);\n// CustomViewTypes.set(elementType, ViewClass);\n// return ViewClass;\n// }\n// }\n\n// export function getBaseViewClassByHTMLElementType(elementType?: TypeOf<HTMLElement>, isFormAssociated?: boolean) {\n// if (elementType && CustomViewTypes.has(elementType)) {\n// return CustomViewTypes.get(elementType);\n// }\n// // start to created view class\n// else if (!elementType || elementType === HTMLElement) {\n// return createViewClass(HTMLElement, isFormAssociated || false);\n// }\n// if (CustomViewTypes.has(elementType)) {\n// return CustomViewTypes.get(elementType);\n// } else {\n\n// }\n// }\n"]}
package/view/render.d.ts CHANGED
@@ -1,20 +1,16 @@
1
- import { ReactiveScope, ScopeContext, ScopeSubscription, Stack } from '@ibyar/expressions';
1
+ import { ScopeContext, ScopeSubscription, Stack } from '@ibyar/expressions';
2
2
  import { CommentNode, DomStructuralDirectiveNode, DomElementNode, DomFragmentNode, DomNode, LiveTextContent, TextContent, DomAttributeDirectiveNode } from '@ibyar/elements';
3
- import { ComponentRef, ListenerRef } from '../component/component.js';
4
- import { ElementMutation } from './mutation.js';
3
+ import { ListenerRef } from '../component/component.js';
5
4
  import { HTMLComponent } from '../component/custom-element.js';
6
5
  import { AttributeDirective, StructuralDirective } from '../directive/directive.js';
7
- import { TemplateRef } from '../linker/template-ref.js';
8
6
  export declare class ComponentRender<T extends object> {
9
7
  view: HTMLComponent<T>;
10
- componentRef: ComponentRef<T>;
11
- template: DomNode;
12
- nativeElementMutation: ElementMutation;
13
- contextStack: Stack;
14
- templateNameScope: ReactiveScope<{
15
- [templateName: string]: TemplateRef;
16
- }>;
17
- constructor(view: HTMLComponent<T>);
8
+ private subscriptions;
9
+ private componentRef;
10
+ private template;
11
+ private contextStack;
12
+ private templateNameScope;
13
+ constructor(view: HTMLComponent<T>, subscriptions: ScopeSubscription<ScopeContext>[]);
18
14
  initView(): void;
19
15
  isTemplateRefName(template: DomNode): template is DomElementNode;
20
16
  initTemplateRefMap(domNode: DomNode): void;
@@ -22,17 +18,17 @@ export declare class ComponentRender<T extends object> {
22
18
  handelHostListener(listener: ListenerRef): void;
23
19
  addNativeEventListener(source: HTMLElement | Window, eventName: string, funcCallback: Function): void;
24
20
  getElementByName(name: string): any;
25
- createStructuralDirective(directive: DomStructuralDirectiveNode, comment: Comment, directiveStack: Stack, parentNode: Node): void;
21
+ createStructuralDirective(directive: DomStructuralDirectiveNode, comment: Comment, directiveStack: Stack, parentNode: Node, host: HTMLComponent<any> | StructuralDirective): void;
26
22
  createComment(node: CommentNode): Comment;
27
23
  createText(node: TextContent): Text;
28
- createLiveText(textNode: LiveTextContent, contextStack: Stack, parentNode: Node): Text;
29
- createDocumentFragment(node: DomFragmentNode, contextStack: Stack, parentNode: Node): DocumentFragment;
30
- appendChildToParent(fragmentParent: HTMLElement | DocumentFragment, child: DomNode, contextStack: Stack, parentNode: Node): void;
24
+ createLiveText(textNode: LiveTextContent, contextStack: Stack, parentNode: Node, subscriptions: ScopeSubscription<ScopeContext>[]): Text;
25
+ createDocumentFragment(node: DomFragmentNode, contextStack: Stack, parentNode: Node, subscriptions: ScopeSubscription<ScopeContext>[], host: HTMLComponent<any> | StructuralDirective): DocumentFragment;
26
+ appendChildToParent(fragmentParent: HTMLElement | DocumentFragment, child: DomNode, contextStack: Stack, parentNode: Node, subscriptions: ScopeSubscription<ScopeContext>[], host: HTMLComponent<any> | StructuralDirective): void;
31
27
  createElementByTagName(node: {
32
28
  tagName: string;
33
29
  is?: string;
34
30
  }): HTMLElement;
35
- createElement(node: DomElementNode, contextStack: Stack, parentNode: Node): HTMLElement;
31
+ createElement(node: DomElementNode, contextStack: Stack, parentNode: Node, subscriptions: ScopeSubscription<ScopeContext>[], host: HTMLComponent<any> | StructuralDirective): HTMLElement;
36
32
  initAttribute(element: HTMLElement, node: DomElementNode, contextStack: Stack): ScopeSubscription<ScopeContext>[];
37
33
  initDirectiveAttributes(directive: StructuralDirective | AttributeDirective, node: DomStructuralDirectiveNode | DomAttributeDirectiveNode, contextStack: Stack): ScopeSubscription<ScopeContext>[];
38
34
  }
package/view/render.js CHANGED
@@ -1,9 +1,8 @@
1
1
  import { CommentNode, DomStructuralDirectiveNode, DomElementNode, DomFragmentNode, isLiveTextContent, isTagNameNative, isValidCustomElementName, TextContent } from '@ibyar/elements';
2
- import { ElementMutation } from './mutation.js';
3
2
  import { isHTMLComponent } from '../component/custom-element.js';
4
3
  import { documentStack } from '../context/stack.js';
5
4
  import { ClassRegistryProvider } from '../providers/provider.js';
6
- import { isOnDestroy, isOnInit } from '../component/lifecycle.js';
5
+ import { isOnInit } from '../component/lifecycle.js';
7
6
  import { hasAttr } from '../utils/elements-util.js';
8
7
  import { AttributeDirective } from '../directive/directive.js';
9
8
  import { TemplateRefImpl } from '../linker/template-ref.js';
@@ -20,13 +19,13 @@ function getInputEventName(element) {
20
19
  }
21
20
  }
22
21
  export class ComponentRender {
23
- constructor(view) {
22
+ constructor(view, subscriptions) {
24
23
  this.view = view;
24
+ this.subscriptions = subscriptions;
25
25
  this.componentRef = this.view.getComponentRef();
26
26
  this.contextStack = documentStack.copyStack();
27
27
  this.contextStack.pushScope(this.view._modelScope);
28
28
  this.templateNameScope = this.contextStack.pushBlockReactiveScope();
29
- this.nativeElementMutation = new ElementMutation();
30
29
  }
31
30
  initView() {
32
31
  if (this.componentRef.template) {
@@ -52,11 +51,11 @@ export class ComponentRender {
52
51
  this.initTemplateRefMap(this.template);
53
52
  let rootFragment;
54
53
  if (this.template instanceof DomFragmentNode) {
55
- rootFragment = this.createDocumentFragment(this.template, this.contextStack, rootRef);
54
+ rootFragment = this.createDocumentFragment(this.template, this.contextStack, rootRef, this.subscriptions, this.view);
56
55
  }
57
56
  else {
58
57
  rootFragment = document.createDocumentFragment();
59
- this.appendChildToParent(rootFragment, this.template, this.contextStack, rootRef);
58
+ this.appendChildToParent(rootFragment, this.template, this.contextStack, rootRef, this.subscriptions, this.view);
60
59
  }
61
60
  rootRef.append(rootFragment);
62
61
  }
@@ -138,23 +137,17 @@ export class ComponentRender {
138
137
  getElementByName(name) {
139
138
  return Reflect.get(this.view, name);
140
139
  }
141
- createStructuralDirective(directive, comment, directiveStack, parentNode) {
140
+ createStructuralDirective(directive, comment, directiveStack, parentNode, host) {
142
141
  const directiveRef = ClassRegistryProvider.getDirectiveRef(directive.name);
143
142
  if (directiveRef) {
144
- const StructuralDirectiveClass = directiveRef.modelClass;
145
143
  const stack = directiveStack.copyStack();
146
144
  const templateRef = new TemplateRefImpl(this, directive.node, stack, directive.templateExpressions ?? []);
147
145
  const viewContainerRef = new ViewContainerRefImpl(parentNode, comment);
148
- const structural = new StructuralDirectiveClass(templateRef, viewContainerRef);
146
+ const StructuralDirectiveClass = directiveRef.modelClass;
147
+ const structural = new StructuralDirectiveClass(templateRef, viewContainerRef, host);
148
+ templateRef.host = structural;
149
149
  stack.pushBlockReactiveScopeFor({ 'this': structural });
150
150
  const subscriptions = this.initDirectiveAttributes(structural, directive, stack);
151
- const removeSubscription = this.nativeElementMutation.subscribeOnRemoveNode(parentNode, comment, () => {
152
- removeSubscription.unsubscribe();
153
- subscriptions.forEach(subscription => subscription.unsubscribe());
154
- if (isOnDestroy(structural)) {
155
- structural.onDestroy();
156
- }
157
- });
158
151
  if (isOnInit(structural)) {
159
152
  structural.onInit();
160
153
  }
@@ -168,24 +161,21 @@ export class ComponentRender {
168
161
  createText(node) {
169
162
  return new Text(node.value);
170
163
  }
171
- createLiveText(textNode, contextStack, parentNode) {
164
+ createLiveText(textNode, contextStack, parentNode, subscriptions) {
172
165
  const liveText = new Text('');
173
166
  contextStack = contextStack.copyStack();
174
167
  contextStack.pushBlockScopeFor({ this: liveText });
175
- const subscriptions = textNode.expression.subscribe(contextStack, textNode.pipelineNames);
168
+ const textSubscriptions = textNode.expression.subscribe(contextStack, textNode.pipelineNames);
169
+ subscriptions.push(...textSubscriptions);
176
170
  textNode.expression.get(contextStack);
177
- const removeSubscription = this.nativeElementMutation.subscribeOnRemoveNode(parentNode, liveText, () => {
178
- removeSubscription.unsubscribe();
179
- subscriptions.forEach(subscription => subscription.unsubscribe());
180
- });
181
171
  return liveText;
182
172
  }
183
- createDocumentFragment(node, contextStack, parentNode) {
173
+ createDocumentFragment(node, contextStack, parentNode, subscriptions, host) {
184
174
  const fragment = document.createDocumentFragment();
185
- node.children?.forEach(child => this.appendChildToParent(fragment, child, contextStack, parentNode));
175
+ node.children?.forEach(child => this.appendChildToParent(fragment, child, contextStack, parentNode, subscriptions, host));
186
176
  return fragment;
187
177
  }
188
- appendChildToParent(fragmentParent, child, contextStack, parentNode) {
178
+ appendChildToParent(fragmentParent, child, contextStack, parentNode, subscriptions, host) {
189
179
  if (child instanceof DomElementNode) {
190
180
  if (this.isTemplateRefName(child)) {
191
181
  const templateRefName = child.templateRefName;
@@ -193,7 +183,7 @@ export class ComponentRender {
193
183
  this.templateNameScope.set(templateRefName.name, templateRef);
194
184
  return;
195
185
  }
196
- fragmentParent.append(this.createElement(child, contextStack, parentNode));
186
+ fragmentParent.append(this.createElement(child, contextStack, parentNode, subscriptions, host));
197
187
  }
198
188
  else if (child instanceof DomStructuralDirectiveNode) {
199
189
  const commentText = child.name + (typeof child.value == 'string' ? (' = ' + child.value) : '');
@@ -201,10 +191,10 @@ export class ComponentRender {
201
191
  fragmentParent.append(comment);
202
192
  const lastComment = document.createComment(`end ${commentText}`);
203
193
  comment.after(lastComment);
204
- this.createStructuralDirective(child, comment, contextStack, parentNode);
194
+ this.createStructuralDirective(child, comment, contextStack, parentNode, host);
205
195
  }
206
196
  else if (isLiveTextContent(child)) {
207
- fragmentParent.append(this.createLiveText(child, contextStack, parentNode));
197
+ fragmentParent.append(this.createLiveText(child, contextStack, parentNode, subscriptions));
208
198
  }
209
199
  else if (child instanceof TextContent) {
210
200
  fragmentParent.append(this.createText(child));
@@ -213,7 +203,7 @@ export class ComponentRender {
213
203
  fragmentParent.append(this.createComment(child));
214
204
  }
215
205
  else if (child instanceof DomFragmentNode) {
216
- fragmentParent.append(this.createDocumentFragment(child, contextStack, parentNode));
206
+ fragmentParent.append(this.createDocumentFragment(child, contextStack, parentNode, subscriptions, host));
217
207
  }
218
208
  }
219
209
  createElementByTagName(node) {
@@ -241,12 +231,11 @@ export class ComponentRender {
241
231
  }
242
232
  return element;
243
233
  }
244
- createElement(node, contextStack, parentNode) {
234
+ createElement(node, contextStack, parentNode, subscriptions, host) {
245
235
  const element = this.createElementByTagName(node);
246
236
  const elementStack = contextStack.copyStack();
247
237
  const elementScope = isHTMLComponent(element) ? element._viewScope : elementStack.pushBlockReactiveScopeFor({ 'this': element });
248
238
  elementStack.pushScope(elementScope);
249
- const subscriptions = [];
250
239
  if (node.attributeDirectives?.length) {
251
240
  node.attributeDirectives.forEach(directiveNode => {
252
241
  const directiveRef = ClassRegistryProvider.getDirectiveRef(directiveNode.name);
@@ -271,11 +260,6 @@ export class ComponentRender {
271
260
  listener = (event) => inputScope.emit('value', element.value);
272
261
  element.addEventListener(eventName, listener);
273
262
  }
274
- const removeSubscription = this.nativeElementMutation.subscribeOnRemoveNode(parentNode, element, () => {
275
- removeSubscription.unsubscribe();
276
- listener && element.removeEventListener(eventName, listener);
277
- subscriptions.forEach(subscription => subscription.unsubscribe());
278
- });
279
263
  const templateRefName = node.templateRefName;
280
264
  if (templateRefName) {
281
265
  Reflect.set(this.view, templateRefName.name, element);
@@ -286,7 +270,7 @@ export class ComponentRender {
286
270
  }
287
271
  if (node.children) {
288
272
  for (const child of node.children) {
289
- this.appendChildToParent(element, child, elementStack, element);
273
+ this.appendChildToParent(element, child, elementStack, element, subscriptions, host);
290
274
  }
291
275
  }
292
276
  return element;