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 CHANGED
@@ -1,4 +1,4 @@
1
- [![npm version](https://badge.fury.io/js/vsn.svg)](https://badge.fury.io/js/vsn) [![Build Status](https://travis-ci.org/malero/vsn.svg?branch=master)](https://travis-ci.org/malero/vsn) [![codecov](https://codecov.io/gh/malero/vsn/branch/master/graph/badge.svg)](https://codecov.io/gh/malero/vsn) [![npm](https://img.shields.io/npm/dw/vsn.svg)]()
1
+ [![npm version](https://badge.fury.io/js/vsn.svg)](https://badge.fury.io/js/vsn) [![Build Status](https://travis-ci.org/malero/vsn.svg?branch=master)](https://travis-ci.org/malero/vsn) [![codecov](https://codecov.io/gh/malero/vsn/branch/master/graph/badge.svg)](https://codecov.io/gh/malero/vsn) [![npm](https://img.shields.io/npm/dw/vsn.svg)]() [![gzip bundle size](http://img.badgesize.io/https://unpkg.com/vsn@latest/dist/?compression=gzip&style=flat-square)](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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.53",
3
+ "version": "0.1.54",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
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
- this.tree = new Tree(this.getAttributeValue());
14
- await this.tree.prepare(this.tag.scope, this.tag.dom, this.tag);
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
- const value = await this.tree.evaluate(this.tag.scope, this.tag.dom, this.tag);
20
- if (!(value instanceof Scope)) {
21
- throw new Error(`Scope value must be an object, got ${typeof value}`);
22
- }
23
- for (const key of value.data.keys) {
24
- this.tag.scope.set(key, value.data[key]);
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
  });