vsn 0.1.126 → 0.1.128

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 (39) hide show
  1. package/demo/examples/item-filtering.html +45 -0
  2. package/demo/vsn.js +2 -2
  3. package/dist/AST/ElementAttributeNode.d.ts +3 -1
  4. package/dist/AST/ElementAttributeNode.js +41 -8
  5. package/dist/AST/ElementAttributeNode.js.map +1 -1
  6. package/dist/AST/ElementStyleNode.d.ts +3 -1
  7. package/dist/AST/ElementStyleNode.js +22 -3
  8. package/dist/AST/ElementStyleNode.js.map +1 -1
  9. package/dist/AST/ScopeMemberNode.js +2 -1
  10. package/dist/AST/ScopeMemberNode.js.map +1 -1
  11. package/dist/Attribute.d.ts +1 -0
  12. package/dist/Attribute.js +6 -1
  13. package/dist/Attribute.js.map +1 -1
  14. package/dist/DOM/DOMObject.d.ts +2 -2
  15. package/dist/DOM/DOMObject.js +46 -0
  16. package/dist/DOM/DOMObject.js.map +1 -1
  17. package/dist/EventDispatcher.d.ts +1 -0
  18. package/dist/EventDispatcher.js +62 -22
  19. package/dist/EventDispatcher.js.map +1 -1
  20. package/dist/Tag.js +86 -26
  21. package/dist/Tag.js.map +1 -1
  22. package/dist/attributes/StyleVarAttribute.d.ts +10 -0
  23. package/dist/attributes/StyleVarAttribute.js +110 -0
  24. package/dist/attributes/StyleVarAttribute.js.map +1 -0
  25. package/dist/attributes/_imports.d.ts +1 -0
  26. package/dist/attributes/_imports.js +3 -1
  27. package/dist/attributes/_imports.js.map +1 -1
  28. package/dist/version.d.ts +1 -1
  29. package/dist/version.js +1 -1
  30. package/package.json +3 -3
  31. package/src/AST/ElementAttributeNode.ts +24 -3
  32. package/src/AST/ElementStyleNode.ts +14 -3
  33. package/src/Attribute.ts +3 -1
  34. package/src/DOM/DOMObject.ts +2 -2
  35. package/src/EventDispatcher.ts +30 -5
  36. package/src/Tag.ts +11 -1
  37. package/src/attributes/StyleVarAttribute.ts +35 -0
  38. package/src/attributes/_imports.ts +1 -0
  39. package/src/version.ts +1 -1
@@ -49,11 +49,11 @@ export abstract class DOMObject extends EventDispatcher {
49
49
  this._scope = scope;
50
50
  }
51
51
 
52
- public watchAttribute(attr: string) {
52
+ public async watchAttribute(attr: string): Promise<any> {
53
53
 
54
54
  }
55
55
 
56
- public watchStyle(style: string) {
56
+ public async watchStyle(style: string): Promise<any> {
57
57
 
58
58
  }
59
59
 
@@ -30,6 +30,7 @@ export type EventDispatcherCallback = (...args: any[]) => any;
30
30
 
31
31
  export class EventDispatcher {
32
32
  private static sources: EventDispatcher[] = [];
33
+ public static readonly stream: EventDispatcher = new EventDispatcher();
33
34
  private readonly _listeners: EventCallbackList;
34
35
  private readonly _allListeners: EventCallback[] = [];
35
36
  private readonly _relays: EventDispatcher[] = [];
@@ -137,19 +138,35 @@ export class EventDispatcher {
137
138
  }
138
139
 
139
140
  noneWithContext(context: any): number {
140
- let toRemove: EventCallback[] = [],
141
- cnt = 0;
141
+ const toRemoveAll: EventCallback[] = [];
142
+ let cnt = 0;
142
143
 
143
- for(const cb of this._allListeners) {
144
+ for (const cb of this._allListeners) {
144
145
  if(context == cb.context) {
145
- toRemove.push(cb);
146
+ toRemoveAll.push(cb);
146
147
  }
147
148
  }
148
149
 
149
- for(const cb of toRemove) {
150
+ for (const k in this._listeners) {
151
+ const toRemove: EventCallback[] = [];
152
+
153
+ for (const cb of this._listeners[k]) {
154
+ if(context == cb.context) {
155
+ toRemove.push(cb);
156
+ }
157
+ }
158
+
159
+ for (const cb of toRemove) {
160
+ this._listeners[k].splice(this._listeners[k].indexOf(cb), 1);
161
+ cnt++;
162
+ }
163
+ }
164
+
165
+ for (const cb of toRemoveAll) {
150
166
  this._allListeners.splice(this._allListeners.indexOf(cb), 1);
151
167
  cnt++;
152
168
  }
169
+
153
170
  return cnt;
154
171
  }
155
172
 
@@ -180,5 +197,13 @@ export class EventDispatcher {
180
197
  for (const relay of this._relays) {
181
198
  relay.dispatch(event, ...args);
182
199
  }
200
+
201
+ if (this === EventDispatcher.stream)
202
+ return;
203
+
204
+ let streamArgs = args;
205
+ if (args.length > 0 && args[0] !== this)
206
+ streamArgs = [this, ...args];
207
+ EventDispatcher.stream.dispatch(event, ...streamArgs);
183
208
  }
184
209
  }
package/src/Tag.ts CHANGED
@@ -590,6 +590,12 @@ export class Tag extends DOMObject {
590
590
  }
591
591
 
592
592
  public async finalize() {
593
+ const tags: Tag[] = await this.getTagsToBuild() as Tag[];
594
+ for (const tag of tags) {
595
+ for (const attr of tag.getAttributesWithState(AttributeState.Connected)) {
596
+ await attr.finalize();
597
+ }
598
+ }
593
599
  this._state = TagState.Built;
594
600
  this.callOnWrapped('$built', this, this.scope, this.element);
595
601
  this.dispatch('$built', this);
@@ -747,7 +753,7 @@ export class Tag extends DOMObject {
747
753
  return this._scope;
748
754
  }
749
755
 
750
- async watchAttribute(attributeName: string) {
756
+ async watchAttribute(attributeName: string): Promise<Attribute | StandardAttribute> {
751
757
  if (this.attributes.has(attributeName) && this.attributes.get(attributeName) instanceof StandardAttribute) {
752
758
  return this.attributes.get(attributeName);
753
759
  }
@@ -792,6 +798,10 @@ export class Tag extends DOMObject {
792
798
  this.attributes.clear();
793
799
  this._children.forEach(child => child.deconstruct());
794
800
  this._children.length = 0;
801
+ if (this._controller) {
802
+ this._controller.deconstruct();
803
+ this._controller = null;
804
+ }
795
805
  super.deconstruct();
796
806
  }
797
807
  }
@@ -0,0 +1,35 @@
1
+ import {Registry} from "../Registry";
2
+ import {Attribute} from "../Attribute";
3
+ import {Scope} from "../Scope";
4
+ import {ScopeReference} from "../Scope/ScopeReference";
5
+
6
+
7
+ @Registry.attribute('vsn-style-var')
8
+ export class StyleVarAttribute extends Attribute {
9
+ public static readonly canDefer: boolean = false;
10
+ protected key?: string;
11
+ protected styleVar?: string;
12
+ protected boundScope?: Scope;
13
+
14
+ public async connect() {
15
+ let scopeKey: string = this.getAttributeValue();
16
+ let ref: ScopeReference;
17
+ try {
18
+ ref = this.tag.scope.getReference(scopeKey);
19
+ } catch (e) {
20
+ console.error('error', e);
21
+ return;
22
+ }
23
+
24
+ this.key = await ref.getKey();
25
+ this.styleVar = this.getAttributeBinding();
26
+ this.boundScope = await ref.getScope();
27
+ this.boundScope.on(`change:${this.key}`, this.update, this);
28
+
29
+ await super.connect();
30
+ }
31
+
32
+ update(e) {
33
+ this.tag.element.style.setProperty(`--${this.styleVar}`, e.value);
34
+ }
35
+ }
@@ -25,6 +25,7 @@ export {ServiceAttribute} from "./ServiceAttribute";
25
25
  export {SetAttribute} from "./SetAttribute";
26
26
  export {StandardAttribute} from "./StandardAttribute";
27
27
  export {StyleAttribute} from "./StyleAttribute";
28
+ export {StyleVarAttribute} from "./StyleVarAttribute";
28
29
  export {TemplateAttribute} from "./TemplateAttribute";
29
30
  export {TypeAttribute} from "./TypeAttribute";
30
31
  export {XHRAttribute} from "./XHRAttribute";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.126';
1
+ export const VERSION = '0.1.128';
2
2