vsn 0.1.111 → 0.1.112

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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ * Code distributed by Google as part of the polymer project is also
8
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vsn",
3
- "version": "0.1.111",
3
+ "version": "0.1.112",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
@@ -29,8 +29,12 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
29
29
  // @todo: Need to rewrite/refactor this. It's a bit of a mess with element queries.
30
30
  let tags: Tag[] = [];
31
31
  let functionScope: Scope = scope;
32
+ let functionName: string = '';
33
+ let instanceOfScopeMemberNode = false;
32
34
  if (this.fnc instanceof ScopeMemberNode) {
35
+ instanceOfScopeMemberNode = true
33
36
  functionScope = await this.fnc.scope.evaluate(scope, dom, tag);
37
+ functionName = await this.fnc.name.evaluate(scope, dom, tag);
34
38
  if (this.fnc.scope instanceof ElementQueryNode) {
35
39
  const _tags = await this.fnc.scope.evaluate(scope, dom, tag);
36
40
  if (_tags instanceof Array) {
@@ -47,6 +51,7 @@ export class FunctionCallNode<T = any> extends Node implements TreeNode {
47
51
 
48
52
  const values = await this.args.evaluate(scope, dom, tag);
49
53
  let func = await this.fnc.evaluate(scope, dom, tag);
54
+ console.log(tag?.element, functionName, func, scope.keys, functionScope?.keys, instanceOfScopeMemberNode);
50
55
  if (!func || func instanceof Array) {
51
56
  const functionName = await (this.fnc as any).name.evaluate(scope, dom, tag);
52
57
  const returnValues = [];
@@ -51,6 +51,8 @@ export class ScopeMemberNode extends ScopeNodeAbstract implements TreeNode {
51
51
  }
52
52
  const name = await this.name.evaluate(scope, dom, tag);
53
53
  await this.applyModifiers(name, parent, dom, tag);
54
+ if (!parent.get)
55
+ console.log('nani?', parent);
54
56
  const value: any = parent.get(name, false);
55
57
  values.push(value instanceof Scope && value.wrapped || value);
56
58
  }
package/src/Controller.ts CHANGED
@@ -7,6 +7,15 @@ export abstract class Controller extends ScopeData {
7
7
  protected _tag: Tag;
8
8
  protected _element: HTMLElement;
9
9
 
10
+ constructor() {
11
+ super();
12
+ for (const k in this) {
13
+ if (this[k] as any instanceof Function) {
14
+ this.__properties__.push(k);
15
+ }
16
+ }
17
+ }
18
+
10
19
  public get scope(): Scope {
11
20
  return this._scope;
12
21
  }
@@ -24,12 +33,4 @@ export abstract class Controller extends ScopeData {
24
33
  this._tag = tag;
25
34
  this._element = element;
26
35
  }
27
-
28
- public get(key: string): any {
29
- return this._scope?.get(key);
30
- }
31
-
32
- public set(key: string, value: any): void {
33
- this._scope?.set(key, value);
34
- }
35
36
  }
@@ -23,8 +23,8 @@ export class ScopeDataAbstract extends EventDispatcher {
23
23
  return this.getProperty(name);
24
24
  }
25
25
  config = config || {};
26
- const instance = new propertyType(config.default, config),
27
- propDesc = Object.getOwnPropertyDescriptor(this, name);
26
+ const instance = new propertyType(config.default, config);
27
+ const propDesc = Object.getOwnPropertyDescriptor(this, name);
28
28
  this['__'+name] = instance;
29
29
  this.__properties__.push(name);
30
30
 
@@ -101,11 +101,11 @@ export class ScopeDataAbstract extends EventDispatcher {
101
101
  return data;
102
102
  }
103
103
 
104
- get(key: string) {
104
+ public get(key: string) {
105
105
  return this[key];
106
106
  }
107
107
 
108
- set(key: string, value: any) {
108
+ public set(key: string, value: any) {
109
109
  this[key] = value;
110
110
  }
111
111
 
package/src/Tag.ts CHANGED
@@ -38,7 +38,8 @@ export class Tag extends DOMObject {
38
38
  '@text',
39
39
  '@html',
40
40
  '@class',
41
- '@value'
41
+ '@value',
42
+ '@disabled'
42
43
  ];
43
44
 
44
45
  protected inputTags: string[] = [
@@ -395,6 +396,12 @@ export class Tag extends DOMObject {
395
396
  const classes: string[] = value instanceof Array ? value : [value];
396
397
  if (classes.length)
397
398
  this.element.classList.add(...classes);
399
+ } else if (key === '@disabled') {
400
+ if (!!value) {
401
+ this.element.setAttribute('disabled', '');
402
+ } else {
403
+ this.element.removeAttribute('disabled');
404
+ }
398
405
  }
399
406
  } else {
400
407
  this.element.setAttribute(key, value);
@@ -411,6 +418,8 @@ export class Tag extends DOMObject {
411
418
  return this.value;
412
419
  else if (key === '@class') {
413
420
  return Array.from(this.element.classList);
421
+ } else if (key === '@disabled') {
422
+ return this.element.hasAttribute('disabled');
414
423
  }
415
424
  }
416
425
  return this.element.getAttribute(key);
@@ -1,34 +1,32 @@
1
1
  import {Scope} from "../Scope";
2
2
  import {Attribute} from "../Attribute";
3
3
  import {Registry} from "../Registry";
4
+ import {Controller} from "../Controller";
4
5
 
5
6
  @Registry.attribute('vsn-controller')
6
7
  export class ControllerAttribute extends Attribute {
7
8
  public static readonly canDefer: boolean = false;
8
9
  public static readonly scoped: boolean = true;
9
10
  public readonly registryName: string = 'controllers'
10
- public readonly assignToParent: boolean = true;
11
11
  protected attributeKey: string;
12
12
  protected className: string;
13
13
  protected defaultClassName: string;
14
14
 
15
15
  public async setup() {
16
- const parentScope: Scope = this.tag.parentTag.scope;
17
- if (!parentScope)
18
- return;
19
-
20
16
  this.attributeKey = this.getAttributeBinding();
21
17
  this.className = this.getAttributeValue(this.defaultClassName);
22
-
23
18
  const cls = await Registry.instance[this.registryName].get(this.className);
24
- const obj = this.instantiateClass(cls);
25
19
 
26
- if (this.attributeKey && obj) {
27
- if (this.assignToParent && parentScope) {
28
- parentScope.set(this.attributeKey, obj);
29
- } else {
30
- this.tag.scope.set(this.attributeKey, obj);
20
+ if (this.attributeKey) {
21
+ const controllerScope = new Scope(this.tag.scope);
22
+ const obj = new cls();
23
+ if (obj instanceof Controller) {
24
+ obj.init(this.tag.scope, this.tag, this.tag.element);
31
25
  }
26
+ controllerScope.wrap(obj);
27
+ this.tag.scope.set(this.attributeKey, controllerScope);
28
+ } else {
29
+ this.instantiateClass(cls);
32
30
  }
33
31
  await super.setup();
34
32
  }
@@ -21,7 +21,7 @@ export class SetAttribute extends Attribute {
21
21
  return this.boundScope.get(this.key, false);
22
22
  }
23
23
 
24
- public async setup() {
24
+ public async extract() {
25
25
  this.property = this.getAttributeBinding();
26
26
  let ref: ScopeReference;
27
27
  try {
@@ -31,10 +31,6 @@ export class SetAttribute extends Attribute {
31
31
  }
32
32
  this.key = await ref.getKey();
33
33
  this.boundScope = await ref.getScope();
34
- await super.setup();
35
- }
36
-
37
- public async extract() {
38
34
  let value = this.getAttributeValue(null);
39
35
  for (const m of this.getAttributeModifiers()) {
40
36
  const t = Registry.instance.types.getSynchronous(m);
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.111';
1
+ export const VERSION = '0.1.112';
2
2
 
@@ -28,15 +28,18 @@ class TestController extends Controller {
28
28
  describe('Controller', () => {
29
29
  it("methods should be callable from vsn-script", async () => {
30
30
  document.body.innerHTML = `
31
- <div vsn-controller:test="ControllerTestController" vsn-set:test.test="notTest" vsn-bind="test.test"></div>
31
+ <div id="controller" vsn-controller:test="ControllerTestController" vsn-set:test.test="notTest" vsn-bind="test.test"></div>
32
32
  `;
33
33
  const dom = new DOM(document);
34
34
  const deferred = SimplePromise.defer();
35
35
  dom.once('built', async () => {
36
- expect(await dom.exec('test.test')).toBe('notTest');
37
- expect(await dom.exec('test.isValid()')).toBe(false);
38
- await dom.exec('test.test = "test"');
39
- expect(await dom.exec('test.isValid()')).toBe(true);
36
+ const tag = await dom.exec('#controller');
37
+ expect(tag.scope.keys).toEqual(['test']);
38
+ expect(tag.scope.get('test').wrapped).toBeInstanceOf(TestController);
39
+ expect(await tag.exec('test.isValid()')).toBe(false);
40
+ expect(await tag.exec('test.test')).toBe('notTest');
41
+ await tag.exec('test.test = "test"');
42
+ expect(await tag.exec('test.isValid()')).toBe(true);
40
43
  deferred.resolve();
41
44
  });
42
45
  await deferred.promise;