vasille 2.0.3 → 2.2.0
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 +7 -3
- package/cdn/es2015.js +939 -1009
- package/cdn/es5.js +1048 -1029
- package/flow-typed/vasille.js +2641 -832
- package/lib/binding/attribute.js +11 -12
- package/lib/binding/binding.js +9 -19
- package/lib/binding/class.js +34 -42
- package/lib/binding/style.js +5 -11
- package/lib/core/core.js +78 -32
- package/lib/core/destroyable.js +2 -2
- package/lib/core/ivalue.js +15 -13
- package/lib/functional/components.js +17 -0
- package/lib/functional/merge.js +41 -0
- package/lib/functional/models.js +26 -0
- package/lib/functional/options.js +1 -0
- package/lib/functional/reactivity.js +33 -0
- package/lib/functional/stack.js +127 -0
- package/lib/index.js +2 -7
- package/lib/models/array-model.js +9 -0
- package/lib/models/object-model.js +28 -14
- package/lib/node/app.js +23 -14
- package/lib/node/interceptor.js +3 -3
- package/lib/node/node.js +338 -684
- package/lib/node/watch.js +9 -17
- package/lib/spec/html.js +1 -0
- package/lib/spec/react.js +1 -0
- package/lib/spec/svg.js +1 -0
- package/lib/v/index.js +23 -0
- package/lib/value/expression.js +11 -8
- package/lib/value/mirror.js +6 -8
- package/lib/value/reference.js +3 -7
- package/lib/views/array-view.js +6 -10
- package/lib/views/base-view.js +12 -23
- package/lib/views/map-view.js +4 -9
- package/lib/views/object-view.js +5 -8
- package/lib/views/repeat-node.js +20 -60
- package/lib/views/repeater.js +7 -7
- package/lib/views/set-view.js +4 -11
- package/package.json +7 -6
- package/types/binding/attribute.d.ts +2 -8
- package/types/binding/binding.d.ts +4 -13
- package/types/binding/class.d.ts +7 -19
- package/types/binding/style.d.ts +0 -6
- package/types/core/core.d.ts +40 -54
- package/types/core/destroyable.d.ts +2 -2
- package/types/core/ivalue.d.ts +13 -11
- package/types/functional/components.d.ts +4 -0
- package/types/functional/merge.d.ts +1 -0
- package/types/functional/models.d.ts +10 -0
- package/types/functional/options.d.ts +23 -0
- package/types/functional/reactivity.d.ts +11 -0
- package/types/functional/stack.d.ts +24 -0
- package/types/index.d.ts +3 -7
- package/types/models/array-model.d.ts +3 -2
- package/types/models/map-model.d.ts +2 -2
- package/types/models/model.d.ts +3 -1
- package/types/models/object-model.d.ts +4 -2
- package/types/models/set-model.d.ts +2 -2
- package/types/node/app.d.ts +21 -19
- package/types/node/node.d.ts +97 -422
- package/types/node/watch.d.ts +9 -15
- package/types/spec/html.d.ts +975 -0
- package/types/spec/react.d.ts +4 -0
- package/types/spec/svg.d.ts +314 -0
- package/types/v/index.d.ts +32 -0
- package/types/value/expression.d.ts +7 -20
- package/types/value/mirror.d.ts +3 -3
- package/types/value/reference.d.ts +5 -5
- package/types/views/array-view.d.ts +3 -4
- package/types/views/base-view.d.ts +9 -17
- package/types/views/map-view.d.ts +2 -3
- package/types/views/object-view.d.ts +2 -3
- package/types/views/repeat-node.d.ts +8 -9
- package/types/views/set-view.d.ts +2 -3
- package/types/core/executor.d.ts +0 -87
- package/types/core/signal.d.ts +0 -35
- package/types/core/slot.d.ts +0 -45
- package/types/node/interceptor.d.ts +0 -50
- package/types/views/repeater.d.ts +0 -38
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Component, Extension, Fragment } from "../node/node";
|
|
2
|
+
import { App } from "../node/app";
|
|
3
|
+
import { current } from "../core/core";
|
|
4
|
+
import { ArrayModel } from "../models/array-model";
|
|
5
|
+
import { ArrayView } from "../views/array-view";
|
|
6
|
+
import { MapModel } from "../models/map-model";
|
|
7
|
+
import { MapView } from "../views/map-view";
|
|
8
|
+
import { SetModel } from "../models/set-model";
|
|
9
|
+
import { SetView } from "../views/set-view";
|
|
10
|
+
import { ObjectModel } from "../models/object-model";
|
|
11
|
+
import { ObjectView } from "../views/object-view";
|
|
12
|
+
import { Watch } from "../node/watch";
|
|
13
|
+
import { userError } from "../core/errors";
|
|
14
|
+
export function app(renderer) {
|
|
15
|
+
return (node, opts) => {
|
|
16
|
+
return new App(node, opts).runFunctional(renderer, opts);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function component(renderer) {
|
|
20
|
+
return (opts, callback) => {
|
|
21
|
+
const component = new Component(opts);
|
|
22
|
+
if (!(current instanceof Fragment))
|
|
23
|
+
throw userError('missing parent node', 'out-of-context');
|
|
24
|
+
let ret;
|
|
25
|
+
if (callback)
|
|
26
|
+
opts.slot = callback;
|
|
27
|
+
current.create(component, node => {
|
|
28
|
+
ret = node.runFunctional(renderer, opts);
|
|
29
|
+
});
|
|
30
|
+
return ret;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function fragment(renderer) {
|
|
34
|
+
return (opts, callback) => {
|
|
35
|
+
const frag = new Fragment(opts);
|
|
36
|
+
if (!(current instanceof Fragment))
|
|
37
|
+
throw userError('missing parent node', 'out-of-context');
|
|
38
|
+
if (callback)
|
|
39
|
+
opts.slot = callback;
|
|
40
|
+
current.create(frag);
|
|
41
|
+
return frag.runFunctional(renderer, opts);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function extension(renderer) {
|
|
45
|
+
return (opts, callback) => {
|
|
46
|
+
const ext = new Extension(opts);
|
|
47
|
+
if (!(current instanceof Fragment))
|
|
48
|
+
throw userError('missing parent node', 'out-of-context');
|
|
49
|
+
if (callback)
|
|
50
|
+
opts.slot = callback;
|
|
51
|
+
current.create(ext);
|
|
52
|
+
return ext.runFunctional(renderer, opts);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function tag(name, opts, callback) {
|
|
56
|
+
if (!(current instanceof Fragment))
|
|
57
|
+
throw userError('missing parent node', 'out-of-context');
|
|
58
|
+
return {
|
|
59
|
+
node: current.tag(name, opts, (node) => {
|
|
60
|
+
callback && node.runFunctional(callback);
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function create(node, callback) {
|
|
65
|
+
if (!(current instanceof Fragment))
|
|
66
|
+
throw userError('missing current node', 'out-of-context');
|
|
67
|
+
current.create(node, (node, ...args) => {
|
|
68
|
+
callback && node.runFunctional(callback, ...args);
|
|
69
|
+
});
|
|
70
|
+
return node;
|
|
71
|
+
}
|
|
72
|
+
export const vx = {
|
|
73
|
+
if(condition, callback) {
|
|
74
|
+
if (current instanceof Fragment) {
|
|
75
|
+
current.if(condition, node => node.runFunctional(callback));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
throw userError("wrong use of `v.if` function", "logic-error");
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
else(callback) {
|
|
82
|
+
if (current instanceof Fragment) {
|
|
83
|
+
current.else(node => node.runFunctional(callback));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw userError("wrong use of `v.else` function", "logic-error");
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
elif(condition, callback) {
|
|
90
|
+
if (current instanceof Fragment) {
|
|
91
|
+
current.elif(condition, node => node.runFunctional(callback));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
throw userError("wrong use of `v.elif` function", "logic-error");
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
for(model, callback) {
|
|
98
|
+
if (model instanceof ArrayModel) {
|
|
99
|
+
// for arrays T & K are the same type
|
|
100
|
+
create(new ArrayView({ model }), callback);
|
|
101
|
+
}
|
|
102
|
+
else if (model instanceof MapModel) {
|
|
103
|
+
create(new MapView({ model }), callback);
|
|
104
|
+
}
|
|
105
|
+
else if (model instanceof SetModel) {
|
|
106
|
+
// for sets T & K are the same type
|
|
107
|
+
create(new SetView({ model }), callback);
|
|
108
|
+
}
|
|
109
|
+
else if (model instanceof ObjectModel) {
|
|
110
|
+
// for objects K is always string
|
|
111
|
+
create(new ObjectView({ model }), callback);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw userError("wrong use of `v.for` function", 'wrong-model');
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
watch(model, callback) {
|
|
118
|
+
const opts = { model };
|
|
119
|
+
create(new Watch(opts), callback);
|
|
120
|
+
},
|
|
121
|
+
nextTick(callback) {
|
|
122
|
+
const node = current;
|
|
123
|
+
window.setTimeout(() => {
|
|
124
|
+
node.runFunctional(callback);
|
|
125
|
+
}, 0);
|
|
126
|
+
}
|
|
127
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { Destroyable } from "./core/destroyable";
|
|
2
|
-
import { Executor, InstantExecutor, TimeoutExecutor } from "./core/executor";
|
|
3
2
|
import { Reactive } from "./core/core";
|
|
4
3
|
import { IValue } from "./core/ivalue";
|
|
5
|
-
import { Signal } from "./core/signal";
|
|
6
|
-
import { Slot } from "./core/slot";
|
|
7
4
|
import { ArrayModel } from "./models/array-model";
|
|
8
5
|
import { Listener } from "./models/listener";
|
|
9
6
|
import { MapModel } from "./models/map-model";
|
|
10
7
|
import { ObjectModel } from "./models/object-model";
|
|
11
8
|
import { SetModel } from "./models/set-model";
|
|
12
9
|
import { App, AppNode } from "./node/app";
|
|
13
|
-
import { Interceptor, InterceptorNode } from "./node/interceptor";
|
|
14
10
|
import { Component, Extension, Fragment, INode, Tag } from "./node/node";
|
|
15
11
|
import { Expression } from "./value/expression";
|
|
16
12
|
import { Mirror } from "./value/mirror";
|
|
@@ -20,8 +16,7 @@ import { ArrayView } from "./views/array-view";
|
|
|
20
16
|
import { BaseView } from "./views/base-view";
|
|
21
17
|
import { MapView } from "./views/map-view";
|
|
22
18
|
import { ObjectView } from "./views/object-view";
|
|
23
|
-
import { RepeatNode } from "./views/repeat-node";
|
|
24
|
-
import { Repeater } from "./views/repeater";
|
|
25
19
|
import { SetView } from "./views/set-view";
|
|
26
20
|
import { Binding } from "./binding/binding";
|
|
27
|
-
|
|
21
|
+
import * as libV from "./v/index";
|
|
22
|
+
export { Destroyable, IValue, Reference, Mirror, Pointer, ArrayModel, MapModel, ObjectModel, SetModel, BaseView, Listener, ArrayView, MapView, ObjectView, SetView, Fragment, INode, Tag, Component, Extension, AppNode, App, Expression, Binding, Reactive, libV };
|
|
@@ -19,6 +19,15 @@ export class ArrayModel extends Array {
|
|
|
19
19
|
super.push(data[i]);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
// proxy
|
|
23
|
+
proxy() {
|
|
24
|
+
return new Proxy(this, {
|
|
25
|
+
set(target, p, value) {
|
|
26
|
+
target.splice(parseInt(p), 1, value);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
22
31
|
/* Array members */
|
|
23
32
|
/**
|
|
24
33
|
* Gets the last item of array
|
|
@@ -10,13 +10,14 @@ export class ObjectModel extends Object {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor(obj = {}) {
|
|
12
12
|
super();
|
|
13
|
+
this.container = Object.create(null);
|
|
13
14
|
Object.defineProperty(this, 'listener', {
|
|
14
15
|
value: new Listener,
|
|
15
16
|
writable: false,
|
|
16
17
|
configurable: false
|
|
17
18
|
});
|
|
18
19
|
for (const i in obj) {
|
|
19
|
-
Object.defineProperty(this, i, {
|
|
20
|
+
Object.defineProperty(this.container, i, {
|
|
20
21
|
value: obj[i],
|
|
21
22
|
configurable: true,
|
|
22
23
|
writable: true,
|
|
@@ -31,8 +32,7 @@ export class ObjectModel extends Object {
|
|
|
31
32
|
* @return {*}
|
|
32
33
|
*/
|
|
33
34
|
get(key) {
|
|
34
|
-
|
|
35
|
-
return ts[key];
|
|
35
|
+
return this.container[key];
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Sets an object property value
|
|
@@ -41,21 +41,19 @@ export class ObjectModel extends Object {
|
|
|
41
41
|
* @return {ObjectModel} a pointer to this
|
|
42
42
|
*/
|
|
43
43
|
set(key, v) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this.listener.emitRemoved(key, ts[key]);
|
|
48
|
-
ts[key] = v;
|
|
44
|
+
if (Reflect.has(this.container, key)) {
|
|
45
|
+
this.listener.emitRemoved(key, this.container[key]);
|
|
46
|
+
this.container[key] = v;
|
|
49
47
|
}
|
|
50
48
|
else {
|
|
51
|
-
Object.defineProperty(
|
|
49
|
+
Object.defineProperty(this.container, key, {
|
|
52
50
|
value: v,
|
|
53
51
|
configurable: true,
|
|
54
52
|
writable: true,
|
|
55
53
|
enumerable: true
|
|
56
54
|
});
|
|
57
55
|
}
|
|
58
|
-
this.listener.emitAdded(key,
|
|
56
|
+
this.listener.emitAdded(key, this.container[key]);
|
|
59
57
|
return this;
|
|
60
58
|
}
|
|
61
59
|
/**
|
|
@@ -63,12 +61,28 @@ export class ObjectModel extends Object {
|
|
|
63
61
|
* @param key {string} property name
|
|
64
62
|
*/
|
|
65
63
|
delete(key) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.
|
|
69
|
-
delete ts[key];
|
|
64
|
+
if (this.container[key]) {
|
|
65
|
+
this.listener.emitRemoved(key, this.container[key]);
|
|
66
|
+
delete this.container[key];
|
|
70
67
|
}
|
|
71
68
|
}
|
|
69
|
+
proxy() {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
71
|
+
const ts = this;
|
|
72
|
+
return new Proxy(this.container, {
|
|
73
|
+
get(target, p) {
|
|
74
|
+
return ts.get(p);
|
|
75
|
+
},
|
|
76
|
+
set(target, p, value) {
|
|
77
|
+
ts.set(p, value);
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
deleteProperty(target, p) {
|
|
81
|
+
ts.delete(p);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
72
86
|
enableReactivity() {
|
|
73
87
|
this.listener.enableReactivity();
|
|
74
88
|
}
|
package/lib/node/app.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { instantExecutor, timeoutExecutor } from "../core/executor";
|
|
2
1
|
import { INode } from "./node";
|
|
3
2
|
/**
|
|
4
3
|
* Application Node
|
|
@@ -7,12 +6,12 @@ import { INode } from "./node";
|
|
|
7
6
|
*/
|
|
8
7
|
export class AppNode extends INode {
|
|
9
8
|
/**
|
|
10
|
-
* @param
|
|
9
|
+
* @param input
|
|
11
10
|
*/
|
|
12
|
-
constructor(
|
|
13
|
-
super();
|
|
14
|
-
this
|
|
15
|
-
this
|
|
11
|
+
constructor(input) {
|
|
12
|
+
super(input);
|
|
13
|
+
this.debugUi = input.debugUi || false;
|
|
14
|
+
this.seal();
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
@@ -24,16 +23,26 @@ export class App extends AppNode {
|
|
|
24
23
|
/**
|
|
25
24
|
* Constructs an app node
|
|
26
25
|
* @param node {Element} The root of application
|
|
27
|
-
* @param
|
|
26
|
+
* @param input
|
|
28
27
|
*/
|
|
29
|
-
constructor(node,
|
|
30
|
-
super(
|
|
28
|
+
constructor(node, input) {
|
|
29
|
+
super(input);
|
|
31
30
|
this.$.node = node;
|
|
32
|
-
this
|
|
33
|
-
this
|
|
31
|
+
this.preinit(this, this);
|
|
32
|
+
this.init();
|
|
33
|
+
this.seal();
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
appendNode(node) {
|
|
36
|
+
this.$.node.appendChild(node);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export class Portal extends AppNode {
|
|
40
|
+
constructor(input) {
|
|
41
|
+
super(input);
|
|
42
|
+
this.$.node = input.node;
|
|
43
|
+
this.seal();
|
|
44
|
+
}
|
|
45
|
+
appendNode(node) {
|
|
46
|
+
this.$.node.appendChild(node);
|
|
38
47
|
}
|
|
39
48
|
}
|
package/lib/node/interceptor.js
CHANGED
|
@@ -49,8 +49,8 @@ export class Interceptor extends Destroyable {
|
|
|
49
49
|
signal.unsubscribe(handler);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
super
|
|
52
|
+
destroy() {
|
|
53
|
+
super.destroy();
|
|
54
54
|
this.signals.forEach(signal => {
|
|
55
55
|
this.handlers.forEach(handler => {
|
|
56
56
|
signal.unsubscribe(handler);
|
|
@@ -77,7 +77,7 @@ export class InterceptorNode extends Fragment {
|
|
|
77
77
|
*/
|
|
78
78
|
this.slot = new Slot;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
compose() {
|
|
81
81
|
this.slot.release(this, this.interceptor);
|
|
82
82
|
}
|
|
83
83
|
}
|