vsn 0.1.86 → 0.1.87

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.86",
3
+ "version": "0.1.87",
4
4
  "description": "SEO Friendly Javascript/Typescript Framework",
5
5
  "keywords": [
6
6
  "framework",
package/src/Registry.ts CHANGED
@@ -68,6 +68,7 @@ export class Registry extends EventDispatcher {
68
68
  public readonly classes: RegistryStore;
69
69
  public readonly models: RegistryStore;
70
70
  public readonly templates: RegistryStore;
71
+ public readonly services: RegistryStore;
71
72
  public readonly types: RegistryStore;
72
73
  public readonly validators: RegistryStore;
73
74
  public readonly formats: RegistryStore;
@@ -81,6 +82,7 @@ export class Registry extends EventDispatcher {
81
82
  this.classes = new RegistryStore();
82
83
  this.models = new RegistryStore();
83
84
  this.templates = new RegistryStore<HTMLTemplateElement>();
85
+ this.services = new RegistryStore();
84
86
  this.types = new RegistryStore();
85
87
  this.validators = new RegistryStore();
86
88
  this.formats = new RegistryStore();
@@ -111,6 +113,10 @@ export class Registry extends EventDispatcher {
111
113
  return register('templates', key, setup);
112
114
  }
113
115
 
116
+ public static service(key: string = null, setup = null) {
117
+ return register('services', key, setup);
118
+ }
119
+
114
120
  public static type(key: string = null, setup = null) {
115
121
  return register('types', key, setup);
116
122
  }
package/src/Service.ts ADDED
@@ -0,0 +1,24 @@
1
+ import {ScopeData} from "./Scope/ScopeData";
2
+ import {Scope} from "./Scope";
3
+
4
+ export class Service extends ScopeData {
5
+ protected static _instance: Service;
6
+ protected _scope: Scope;
7
+
8
+ constructor() {
9
+ super();
10
+ this._scope = new Scope();
11
+ this._scope.wrap(this);
12
+ }
13
+
14
+ public get scope(): Scope {
15
+ return this._scope;
16
+ }
17
+
18
+ public static get instance(): Service {
19
+ if (!this._instance) {
20
+ this._instance = new this();
21
+ }
22
+ return this._instance;
23
+ }
24
+ }
@@ -6,6 +6,8 @@ import {Registry} from "../Registry";
6
6
  export class ControllerAttribute extends Attribute {
7
7
  public static readonly canDefer: boolean = false;
8
8
  public static readonly scoped: boolean = true;
9
+ public readonly registryName: string = 'controllers'
10
+ public readonly assignToParent: boolean = true;
9
11
  protected attributeKey: string;
10
12
  protected className: string;
11
13
  protected defaultClassName: string;
@@ -18,15 +20,21 @@ export class ControllerAttribute extends Attribute {
18
20
  this.attributeKey = this.getAttributeBinding();
19
21
  this.className = this.getAttributeValue(this.defaultClassName);
20
22
 
21
- const cls = await Registry.instance.controllers.get(this.className);
22
- this.instantiateClass(cls);
23
+ const cls = await Registry.instance[this.registryName].get(this.className);
24
+ const obj = this.instantiateClass(cls);
23
25
 
24
- if (this.attributeKey && parentScope)
25
- parentScope.set(this.attributeKey, this.tag.scope);
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);
31
+ }
32
+ }
26
33
  await super.setup();
27
34
  }
28
35
 
29
- protected instantiateClass(cls) {
36
+ protected instantiateClass(cls): any {
30
37
  this.tag.wrap(cls);
38
+ return this.tag.scope;
31
39
  }
32
40
  }
@@ -1,5 +1,8 @@
1
1
  import {ControllerAttribute} from "./ControllerAttribute";
2
+ import {Registry} from "../Registry";
2
3
 
4
+ @Registry.attribute('vsn-model')
3
5
  export class ModelAttribute extends ControllerAttribute {
4
6
  public static readonly canDefer: boolean = false;
7
+ public readonly registryName: string = 'models'
5
8
  }
@@ -0,0 +1,13 @@
1
+ import {ControllerAttribute} from "./ControllerAttribute";
2
+ import {Registry} from "../Registry";
3
+
4
+ @Registry.attribute('vsn-service')
5
+ export class ServiceAttribute extends ControllerAttribute {
6
+ public static readonly canDefer: boolean = false;
7
+ public readonly registryName: string = 'services'
8
+ public readonly assignToParent: boolean = false;
9
+
10
+ protected instantiateClass(cls): any {
11
+ return cls.instance.scope;
12
+ }
13
+ }
@@ -21,6 +21,7 @@ export {RootAttribute} from "./RootAttribute";
21
21
  export {ScopeAttribute} from "./ScopeAttribute";
22
22
  export {ScopeChange} from "./ScopeChange";
23
23
  export {ScriptAttribute} from "./ScriptAttribute";
24
+ export {ServiceAttribute} from "./ServiceAttribute";
24
25
  export {SetAttribute} from "./SetAttribute";
25
26
  export {StandardAttribute} from "./StandardAttribute";
26
27
  export {StyleAttribute} from "./StyleAttribute";
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '0.1.86';
1
+ export const VERSION = '0.1.87';
2
2
 
package/src/vsn.ts CHANGED
@@ -91,6 +91,7 @@ export {ScopeReference} from './Scope/ScopeReference';
91
91
  export {WrappedArray} from './Scope/WrappedArray';
92
92
  export {Controller} from './Controller';
93
93
  export {Model} from './Model';
94
+ export {Service} from './Service';
94
95
  export {EventDispatcher} from './EventDispatcher';
95
96
  export {MessageList} from './MessageList';
96
97
  export {SimplePromise} from './SimplePromise';
@@ -0,0 +1,34 @@
1
+ import {DOM} from "../../src/DOM";
2
+ import "../../src/Types";
3
+ import "../../src/attributes/_imports";
4
+ import {Registry} from "../../src/Registry";
5
+ import {Service} from "../../src/Service";
6
+ import {property} from "../../src/Scope/properties/Property";
7
+
8
+
9
+ @Registry.service('TestService')
10
+ class TestService extends Service {
11
+ @property()
12
+ public test: string;
13
+
14
+ constructor() {
15
+ super();
16
+ }
17
+
18
+ }
19
+
20
+
21
+ describe('ServiceAttribute', () => {
22
+ it("vsn-styles to just work", (done) => {
23
+ document.body.innerHTML = `
24
+ <div vsn-service:test1="TestService" id="test"></div>
25
+ <div vsn-service:test2="TestService" vsn-set:test2.test="testing"></div>
26
+ `;
27
+ const dom = new DOM(document);
28
+ dom.once('built', async () => {
29
+ expect(TestService.instance.test).toBe('testing');
30
+ expect(await dom.exec('#test.test1.test')).toBe('testing');
31
+ done();
32
+ });
33
+ });
34
+ });