vsn 0.1.53 → 0.1.54
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/README.md +2 -2
- package/package.json +1 -1
- package/src/Tag.ts +11 -5
- package/src/attributes/ScopeAttribute.ts +14 -8
- package/test/attributes/ScopeAttribute.spec.ts +12 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[](https://badge.fury.io/js/vsn) [](https://travis-ci.org/malero/vsn) [](https://codecov.io/gh/malero/vsn) []()
|
|
1
|
+
[](https://badge.fury.io/js/vsn) [](https://travis-ci.org/malero/vsn) [](https://codecov.io/gh/malero/vsn) []() [](https://unpkg.com/vsn)
|
|
2
2
|
|
|
3
3
|
# VisionJS Framework
|
|
4
4
|
|
|
@@ -12,4 +12,4 @@ Use NPM to install VisionJS with the following command:
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
Please visit the [docs](https://vsnjs.org) for more information.
|
|
15
|
+
Please visit the [docs](https://www.vsnjs.org) for more information.
|
package/package.json
CHANGED
package/src/Tag.ts
CHANGED
|
@@ -250,6 +250,9 @@ export class Tag extends DOMObject {
|
|
|
250
250
|
if (!!this._scope)
|
|
251
251
|
return this._scope;
|
|
252
252
|
|
|
253
|
+
if (this.uniqueScope)
|
|
254
|
+
return this.createScope();
|
|
255
|
+
|
|
253
256
|
if (!!this._parentTag)
|
|
254
257
|
return this._parentTag.scope;
|
|
255
258
|
|
|
@@ -432,7 +435,6 @@ export class Tag extends DOMObject {
|
|
|
432
435
|
|
|
433
436
|
if (requiresScope && !this.uniqueScope) {
|
|
434
437
|
this._uniqueScope = true;
|
|
435
|
-
this._scope = new Scope();
|
|
436
438
|
}
|
|
437
439
|
|
|
438
440
|
this._state = TagState.AttributesBuilt;
|
|
@@ -569,17 +571,21 @@ export class Tag extends DOMObject {
|
|
|
569
571
|
}
|
|
570
572
|
}
|
|
571
573
|
|
|
572
|
-
public createScope() {
|
|
574
|
+
public createScope(force: boolean = false): Scope {
|
|
573
575
|
// Standard attribute requires a unique scope
|
|
574
576
|
// @todo: Does this cause any issues with attribute bindings on the parent scope prior to having its own scope? hmm...
|
|
575
|
-
if (!this.uniqueScope) {
|
|
577
|
+
if ((!this.uniqueScope && force) || this.uniqueScope) {
|
|
576
578
|
this._uniqueScope = true;
|
|
577
579
|
this._scope = new Scope();
|
|
578
580
|
|
|
579
581
|
if (this.parentTag) {
|
|
580
582
|
this.scope.parentScope = this.parentTag.scope;
|
|
581
583
|
}
|
|
584
|
+
|
|
585
|
+
return this._scope;
|
|
582
586
|
}
|
|
587
|
+
|
|
588
|
+
return null;
|
|
583
589
|
}
|
|
584
590
|
|
|
585
591
|
async watchAttribute(attributeName: string) {
|
|
@@ -589,7 +595,7 @@ export class Tag extends DOMObject {
|
|
|
589
595
|
}
|
|
590
596
|
}
|
|
591
597
|
|
|
592
|
-
this.createScope();
|
|
598
|
+
this.createScope(true);
|
|
593
599
|
|
|
594
600
|
const standardAttribute = new StandardAttribute(this, attributeName);
|
|
595
601
|
this.attributes.push(standardAttribute);
|
|
@@ -605,7 +611,7 @@ export class Tag extends DOMObject {
|
|
|
605
611
|
}
|
|
606
612
|
}
|
|
607
613
|
|
|
608
|
-
this.createScope();
|
|
614
|
+
this.createScope(true);
|
|
609
615
|
|
|
610
616
|
const styleAttribute = new StyleAttribute(this, 'style');
|
|
611
617
|
this.attributes.push(styleAttribute);
|
|
@@ -10,18 +10,24 @@ export class ScopeAttribute extends Attribute {
|
|
|
10
10
|
protected tree: Tree;
|
|
11
11
|
|
|
12
12
|
public async compile() {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const code = this.getAttributeValue();
|
|
14
|
+
if (code) {
|
|
15
|
+
this.tree = new Tree(code);
|
|
16
|
+
await this.tree.prepare(this.tag.scope, this.tag.dom, this.tag);
|
|
17
|
+
}
|
|
15
18
|
await super.compile();
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
public async extract() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
if (this.tree) {
|
|
23
|
+
const value = await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
|
|
24
|
+
if (!(value instanceof Scope)) {
|
|
25
|
+
throw new Error(`vsn-scope value must be an object, got ${typeof value}`);
|
|
26
|
+
}
|
|
27
|
+
for (const key of value.data.keys) {
|
|
28
|
+
this.tag.scope.set(key, value.data[key]);
|
|
29
|
+
}
|
|
25
30
|
}
|
|
31
|
+
await super.extract();
|
|
26
32
|
}
|
|
27
33
|
}
|
|
@@ -20,4 +20,16 @@ describe('ScopeAttribute', () => {
|
|
|
20
20
|
done();
|
|
21
21
|
});
|
|
22
22
|
});
|
|
23
|
+
|
|
24
|
+
it("vsn-scope should allow empty value to create a scope", (done) => {
|
|
25
|
+
document.body.innerHTML = `
|
|
26
|
+
<div vsn-scope></div>
|
|
27
|
+
`;
|
|
28
|
+
const dom = new DOM(document);
|
|
29
|
+
dom.once('built', async () => {
|
|
30
|
+
const element = (await dom.exec('?(div)'))[0];
|
|
31
|
+
expect(element.uniqueScope).toBe(true);
|
|
32
|
+
done();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
23
35
|
});
|