vsn 0.1.51 → 0.1.52

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/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
7
- "typescript"
7
+ "typescript",
8
+ "html",
9
+ "ajax",
10
+ "hateoas",
11
+ "rest",
12
+ "seo"
8
13
  ],
9
14
  "main": "./dist/vsn.js",
10
15
  "scripts": {
@@ -1,8 +1,27 @@
1
1
  import {Attribute} from "../Attribute";
2
2
  import {Registry} from "../Registry";
3
+ import {Tree} from "../AST";
4
+ import {Scope} from "../Scope";
3
5
 
4
6
  @Registry.attribute('vsn-scope')
5
7
  export class ScopeAttribute extends Attribute {
6
8
  public static readonly canDefer: boolean = false;
7
9
  public static readonly scoped: boolean = true;
10
+ protected tree: Tree;
11
+
12
+ public async compile() {
13
+ this.tree = new Tree(this.getAttributeValue());
14
+ await this.tree.prepare(this.tag.scope, this.tag.dom, this.tag);
15
+ await super.compile();
16
+ }
17
+
18
+ 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]);
25
+ }
26
+ }
8
27
  }
@@ -0,0 +1,23 @@
1
+ import {DOM} from "../../src/DOM";
2
+ import "../../src/Types";
3
+ import "../../src/attributes/_imports";
4
+
5
+
6
+ describe('ScopeAttribute', () => {
7
+ it("vsn-styles to just work", (done) => {
8
+ document.body.innerHTML = `
9
+ <div vsn-scope="{'asd':123, 'sdf': 'asd'}">
10
+ <span vsn-bind="asd"></span>
11
+ </div>
12
+ `;
13
+ const dom = new DOM(document);
14
+ dom.once('built', async () => {
15
+ const element = (await dom.exec('?(div)'))[0];
16
+ expect(element.scope.get('asd')).toBe(123);
17
+ expect(element.scope.get('sdf')).toBe('asd');
18
+ const span = (await element.exec('?>(:first-child)'))[0];
19
+ expect(span.element.innerText).toBe('123');
20
+ done();
21
+ });
22
+ });
23
+ });