vsn 0.1.84 → 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.
- package/demo/demo.html +176 -36
- package/demo/vsn.js +2 -2
- package/dist/AST/ScopeNodeAbstract.js +2 -1
- package/dist/AST/ScopeNodeAbstract.js.map +1 -1
- package/dist/Model.js +10 -0
- package/dist/Model.js.map +1 -1
- package/dist/Registry.d.ts +2 -0
- package/dist/Registry.js +6 -0
- package/dist/Registry.js.map +1 -1
- package/dist/Scope/ScopeData.js +0 -1
- package/dist/Scope/ScopeData.js.map +1 -1
- package/dist/Scope/ScopeDataAbstract.d.ts +2 -0
- package/dist/Scope/ScopeDataAbstract.js +9 -0
- package/dist/Scope/ScopeDataAbstract.js.map +1 -1
- package/dist/Service.d.ts +9 -0
- package/dist/Service.js +49 -0
- package/dist/Service.js.map +1 -0
- package/dist/attributes/ControllerAttribute.d.ts +3 -1
- package/dist/attributes/ControllerAttribute.js +16 -6
- package/dist/attributes/ControllerAttribute.js.map +1 -1
- package/dist/attributes/List.js +9 -4
- package/dist/attributes/List.js.map +1 -1
- package/dist/attributes/ListItem.js +6 -3
- package/dist/attributes/ListItem.js.map +1 -1
- package/dist/attributes/ModelAttribute.d.ts +1 -0
- package/dist/attributes/ModelAttribute.js +13 -1
- package/dist/attributes/ModelAttribute.js.map +1 -1
- package/dist/attributes/ServiceAttribute.d.ts +7 -0
- package/dist/attributes/ServiceAttribute.js +45 -0
- package/dist/attributes/ServiceAttribute.js.map +1 -0
- package/dist/attributes/_imports.d.ts +1 -0
- package/dist/attributes/_imports.js +3 -1
- package/dist/attributes/_imports.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/vsn.d.ts +1 -0
- package/dist/vsn.js +4 -2
- package/dist/vsn.js.map +1 -1
- package/dist/vsn.min.js +3 -0
- package/dist/vsn.min.js.LICENSE.txt +9 -0
- package/package.json +1 -1
- package/src/AST/ScopeNodeAbstract.ts +1 -1
- package/src/Model.ts +2 -1
- package/src/Registry.ts +6 -0
- package/src/Scope/ScopeData.ts +0 -1
- package/src/Scope/ScopeDataAbstract.ts +11 -0
- package/src/Service.ts +24 -0
- package/src/attributes/ControllerAttribute.ts +13 -5
- package/src/attributes/List.ts +7 -4
- package/src/attributes/ListItem.ts +5 -4
- package/src/attributes/ModelAttribute.ts +3 -0
- package/src/attributes/ServiceAttribute.ts +13 -0
- package/src/attributes/_imports.ts +1 -0
- package/src/version.ts +1 -1
- package/src/vsn.ts +2 -1
- package/test/attributes/ListItem.spec.ts +22 -28
- package/test/attributes/ServiceAttribute.spec.ts +34 -0
|
@@ -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
package/src/Model.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {MessageList} from "./MessageList";
|
|
2
2
|
import {ScopeData} from "./Scope/ScopeData";
|
|
3
3
|
import {IScopeData} from "./Scope/ScopeDataAbstract";
|
|
4
|
+
import {Registry} from "./Registry";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
@Registry.model('Model')
|
|
6
7
|
export class Model extends ScopeData {
|
|
7
8
|
_errors!: MessageList;
|
|
8
9
|
_hasErrors: boolean;
|
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/Scope/ScopeData.ts
CHANGED
|
@@ -19,6 +19,9 @@ export class ScopeDataAbstract extends EventDispatcher {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
createProperty(name: string, propertyType: any = Property, config?: IPropertyConfig): any {
|
|
22
|
+
if (this.hasProperty(name)) {
|
|
23
|
+
return this.getProperty(name);
|
|
24
|
+
}
|
|
22
25
|
config = config || {};
|
|
23
26
|
const instance = new propertyType(config.default, config),
|
|
24
27
|
propDesc = Object.getOwnPropertyDescriptor(this, name);
|
|
@@ -98,6 +101,14 @@ export class ScopeDataAbstract extends EventDispatcher {
|
|
|
98
101
|
return data;
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
get(key: string) {
|
|
105
|
+
return this[key];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
set(key: string, value: any) {
|
|
109
|
+
this[key] = value;
|
|
110
|
+
}
|
|
111
|
+
|
|
101
112
|
getProperties(): string[] {
|
|
102
113
|
return this.__properties__;
|
|
103
114
|
}
|
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.
|
|
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 &&
|
|
25
|
-
|
|
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
|
}
|
package/src/attributes/List.ts
CHANGED
|
@@ -102,7 +102,7 @@ export class List extends Attribute {
|
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
public get listItemModel(): string {
|
|
105
|
-
return this.tag.getRawAttributeValue('vsn-list-item-model'
|
|
105
|
+
return this.tag.getRawAttributeValue('vsn-list-item-model');
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
public remove(item: any) {
|
|
@@ -126,17 +126,20 @@ export class List extends Attribute {
|
|
|
126
126
|
} else {
|
|
127
127
|
element = clone as HTMLElement;
|
|
128
128
|
}
|
|
129
|
+
delete element[Tag.TaggedVariable];
|
|
129
130
|
|
|
130
131
|
this.tag.element.appendChild(element);
|
|
131
132
|
|
|
132
133
|
await this.tag.dom.buildFrom(this.tag.element);
|
|
133
134
|
const tag: Tag = await this.tag.dom.getTagForElement(element);
|
|
134
135
|
this.tags.push(tag);
|
|
135
|
-
tag.scope.clear();
|
|
136
136
|
|
|
137
137
|
if (obj) {
|
|
138
|
-
tag.
|
|
139
|
-
|
|
138
|
+
if (tag.scope.wrapped) {
|
|
139
|
+
tag.scope.data.setData(obj);
|
|
140
|
+
} else {
|
|
141
|
+
tag.wrap(obj);
|
|
142
|
+
}
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
this.tag.dispatch('add', obj);
|
|
@@ -18,11 +18,12 @@ export class ListItem extends Attribute {
|
|
|
18
18
|
this._list = this.tag.findAncestorByAttribute('vsn-list');
|
|
19
19
|
if (!this._list)
|
|
20
20
|
throw Error(ListItem.ERROR_NO_PARENT);
|
|
21
|
-
|
|
22
|
-
this.tag.scope.set(this.listItemName, this.tag.scope);
|
|
23
21
|
const modelName: string = (await this.getList()).listItemModel;
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (modelName) {
|
|
23
|
+
const cls = await Registry.instance.models.get(modelName);
|
|
24
|
+
this.instantiateModel(cls);
|
|
25
|
+
}
|
|
26
|
+
this.tag.scope.set(this.listItemName, this.tag.scope);
|
|
26
27
|
await super.setup();
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -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.
|
|
1
|
+
export const VERSION = '0.1.87';
|
|
2
2
|
|
package/src/vsn.ts
CHANGED
|
@@ -32,7 +32,7 @@ export class Vision extends EventDispatcher {
|
|
|
32
32
|
this.registry.functions.register('warn', console.warn);
|
|
33
33
|
this.registry.functions.register('error', console.error);
|
|
34
34
|
this.registry.functions.register('info', console.info);
|
|
35
|
-
this.registry.
|
|
35
|
+
this.registry.models.register('Object', Object);
|
|
36
36
|
this.registry.controllers.register('WrappedArray', WrappedArray);
|
|
37
37
|
this.registry.controllers.register('Data', DynamicScopeData);
|
|
38
38
|
|
|
@@ -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';
|
|
@@ -4,6 +4,8 @@ import {DOM} from "../../src/DOM";
|
|
|
4
4
|
import {ListItem} from "../../src/attributes/ListItem";
|
|
5
5
|
import {Registry} from "../../src/Registry";
|
|
6
6
|
import {List} from "../../src/attributes/List";
|
|
7
|
+
import {Model} from "../../src/Model";
|
|
8
|
+
import {property} from "../../src/Scope/properties/Property";
|
|
7
9
|
|
|
8
10
|
@Registry.controller('ListItemController')
|
|
9
11
|
class ListItemController{
|
|
@@ -12,26 +14,19 @@ class ListItemController{
|
|
|
12
14
|
do() {}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
@Registry.
|
|
16
|
-
class ListItemSpecTestItem {
|
|
17
|
+
@Registry.model('ListItemSpecTestItem')
|
|
18
|
+
class ListItemSpecTestItem extends Model {
|
|
19
|
+
@property()
|
|
17
20
|
test: number = null;
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
test: number
|
|
22
|
-
) {
|
|
23
|
-
this.test = test;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
getValue() {
|
|
27
|
-
return this.v
|
|
28
|
-
}
|
|
22
|
+
@property()
|
|
23
|
+
v: number;
|
|
29
24
|
}
|
|
30
25
|
|
|
31
26
|
describe('ListItem', () => {
|
|
32
27
|
it("vsn-list-item should find it's parent list or complain", async () => {
|
|
33
28
|
document.body.innerHTML = `
|
|
34
|
-
<ul
|
|
29
|
+
<ul id="test"><li vsn-list-item:item id="test-item"></li></ul>
|
|
35
30
|
`;
|
|
36
31
|
let errorThrown: boolean = false;
|
|
37
32
|
try {
|
|
@@ -46,7 +41,7 @@ describe('ListItem', () => {
|
|
|
46
41
|
|
|
47
42
|
it("vsn-list-item should find it's parent list", (done) => {
|
|
48
43
|
document.body.innerHTML = `
|
|
49
|
-
<ul vsn-list:list id="test"><li vsn-list-item:item
|
|
44
|
+
<ul vsn-list:list vsn-list-item-model="ListItemSpecTestItem" id="test"><li vsn-list-item:item id="test-item"></li></ul>
|
|
50
45
|
`;
|
|
51
46
|
|
|
52
47
|
const dom = new DOM(document);
|
|
@@ -63,8 +58,8 @@ describe('ListItem', () => {
|
|
|
63
58
|
it("should properly wrap list item class", (done) => {
|
|
64
59
|
document.body.innerHTML = `
|
|
65
60
|
<div vsn-controller:controller="ListItemController">
|
|
66
|
-
<ul vsn-list:controller.items id="test">
|
|
67
|
-
<li vsn-template vsn-list-item:item
|
|
61
|
+
<ul vsn-list:controller.items vsn-list-item-model="ListItemSpecTestItem" id="test">
|
|
62
|
+
<li vsn-template vsn-list-item:item></li>
|
|
68
63
|
</ul>
|
|
69
64
|
</div>
|
|
70
65
|
`;
|
|
@@ -77,25 +72,24 @@ describe('ListItem', () => {
|
|
|
77
72
|
list.on('add', () => {
|
|
78
73
|
const listItem = listAttr.tags[0];
|
|
79
74
|
|
|
80
|
-
expect(listItem.scope.
|
|
81
|
-
expect(controller.items[0] instanceof ListItemSpecTestItem).toBeTrue();
|
|
82
|
-
expect(listItem.scope.wrapped === controller.items[0]).toBeTrue();
|
|
75
|
+
expect(listItem.scope.data instanceof ListItemSpecTestItem).toBeTrue();
|
|
83
76
|
expect(controller.items.length).toBe(1);
|
|
84
|
-
expect(controller.items
|
|
85
|
-
|
|
86
|
-
expect(listItem.scope.get('test')).toBe(1);
|
|
87
|
-
expect(listItem.scope.get('v')).toBe(555);
|
|
77
|
+
expect(controller.items[0] instanceof ListItemSpecTestItem).toBeTrue();
|
|
78
|
+
|
|
88
79
|
done();
|
|
89
80
|
});
|
|
90
81
|
|
|
91
82
|
listAttr.items.length = 0;
|
|
92
|
-
listAttr.items.push(new ListItemSpecTestItem(
|
|
83
|
+
listAttr.items.push(new ListItemSpecTestItem({
|
|
84
|
+
test: 1,
|
|
85
|
+
v: 555
|
|
86
|
+
}));
|
|
93
87
|
});
|
|
94
88
|
});
|
|
95
89
|
|
|
96
90
|
it("vsn-list-item should work with vsn-set", (done) => {
|
|
97
91
|
document.body.innerHTML = `
|
|
98
|
-
<ul vsn-list:list id="test"><li vsn-list-item:item
|
|
92
|
+
<ul vsn-list:list vsn-list-item-model="ListItemSpecTestItem" id="test"><li vsn-list-item:item id="test-item" vsn-set:item.testing|integer="1"></li></ul>
|
|
99
93
|
`;
|
|
100
94
|
|
|
101
95
|
const dom = new DOM(document);
|
|
@@ -111,7 +105,7 @@ describe('ListItem', () => {
|
|
|
111
105
|
|
|
112
106
|
it("vsn-list-item should work with vsn-exec", (done) => {
|
|
113
107
|
document.body.innerHTML = `
|
|
114
|
-
<ul vsn-list:list id="test"><li vsn-list-item:item
|
|
108
|
+
<ul vsn-list:list vsn-list-item-model="ListItemSpecTestItem" id="test"><li vsn-list-item:item id="test-item" vsn-exec="item.test = 1"></li></ul>
|
|
115
109
|
`;
|
|
116
110
|
|
|
117
111
|
const dom = new DOM(document);
|
|
@@ -119,8 +113,8 @@ describe('ListItem', () => {
|
|
|
119
113
|
const list = await dom.getTagForElement(document.getElementById('test'));
|
|
120
114
|
const listItem = await dom.getTagForElement(document.getElementById('test-item'));
|
|
121
115
|
const listItemAttr: ListItem = await listItem.getAttribute('vsn-list-item') as ListItem;
|
|
122
|
-
|
|
123
|
-
expect(listItem.scope.get('
|
|
116
|
+
console.log('test keys', listItem.scope.keys);
|
|
117
|
+
expect(listItem.scope.get('test')).toBe(1);
|
|
124
118
|
done();
|
|
125
119
|
});
|
|
126
120
|
});
|
|
@@ -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
|
+
});
|