vasille 2.2.2 → 2.3.2
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 +34 -28
- package/cdn/es2015.js +18 -724
- package/cdn/es5.js +687 -957
- package/flow-typed/vasille.js +14 -59
- package/lib/core/core.js +3 -3
- package/lib/index.js +5 -4
- package/lib/models/array-model.js +6 -9
- package/lib/models/object-model.js +3 -17
- package/lib/node/node.js +6 -3
- package/lib/views/object-view.js +1 -1
- package/lib-node/binding/attribute.js +35 -0
- package/lib-node/binding/binding.js +33 -0
- package/lib-node/binding/class.js +48 -0
- package/lib-node/binding/style.js +27 -0
- package/lib-node/core/core.js +243 -0
- package/lib-node/core/destroyable.js +49 -0
- package/lib-node/core/errors.js +23 -0
- package/lib-node/core/ivalue.js +63 -0
- package/lib-node/functional/options.js +2 -0
- package/lib-node/index.js +54 -0
- package/lib-node/models/array-model.js +218 -0
- package/lib-node/models/listener.js +134 -0
- package/lib-node/models/map-model.js +70 -0
- package/lib-node/models/model.js +2 -0
- package/lib-node/models/object-model.js +82 -0
- package/lib-node/models/set-model.js +66 -0
- package/lib-node/node/app.js +54 -0
- package/lib-node/node/node.js +885 -0
- package/lib-node/node/watch.js +23 -0
- package/lib-node/spec/html.js +2 -0
- package/lib-node/spec/react.js +2 -0
- package/lib-node/spec/svg.js +2 -0
- package/lib-node/value/expression.js +90 -0
- package/lib-node/value/mirror.js +60 -0
- package/lib-node/value/pointer.js +30 -0
- package/lib-node/value/reference.js +55 -0
- package/lib-node/views/array-view.js +21 -0
- package/lib-node/views/base-view.js +43 -0
- package/lib-node/views/map-view.js +18 -0
- package/lib-node/views/object-view.js +20 -0
- package/lib-node/views/repeat-node.js +71 -0
- package/lib-node/views/set-view.js +19 -0
- package/package.json +21 -17
- package/types/core/core.d.ts +4 -4
- package/types/functional/options.d.ts +2 -2
- package/types/index.d.ts +10 -7
- package/types/models/array-model.d.ts +1 -1
- package/types/models/object-model.d.ts +1 -1
- package/types/node/node.d.ts +5 -4
- package/types/node/watch.d.ts +2 -2
- package/types/views/repeat-node.d.ts +2 -2
- package/lib/core/executor.js +0 -154
- package/lib/core/signal.js +0 -50
- package/lib/core/slot.js +0 -47
- package/lib/functional/components.js +0 -17
- package/lib/functional/merge.js +0 -41
- package/lib/functional/models.js +0 -26
- package/lib/functional/reactivity.js +0 -33
- package/lib/functional/stack.js +0 -127
- package/lib/node/interceptor.js +0 -83
- package/lib/v/index.js +0 -23
- package/lib/views/repeater.js +0 -63
- package/types/functional/components.d.ts +0 -4
- package/types/functional/merge.d.ts +0 -1
- package/types/functional/models.d.ts +0 -10
- package/types/functional/reactivity.d.ts +0 -11
- package/types/functional/stack.d.ts +0 -24
- package/types/v/index.d.ts +0 -36
package/types/node/node.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Reactive, ReactivePrivate } from "../core/core";
|
|
2
2
|
import { IValue } from "../core/ivalue";
|
|
3
3
|
import type { AppNode } from "./app";
|
|
4
|
-
import {
|
|
4
|
+
import { FragmentOptions, TagOptions } from "../functional/options";
|
|
5
5
|
import { AcceptedTagsMap } from "../spec/react";
|
|
6
6
|
/**
|
|
7
7
|
* Represents a Vasille.js node
|
|
@@ -45,7 +45,7 @@ export declare class FragmentPrivate extends ReactivePrivate {
|
|
|
45
45
|
* This class is symbolic
|
|
46
46
|
* @extends Reactive
|
|
47
47
|
*/
|
|
48
|
-
export declare class Fragment<T extends
|
|
48
|
+
export declare class Fragment<T extends FragmentOptions = FragmentOptions> extends Reactive {
|
|
49
49
|
/**
|
|
50
50
|
* Private part
|
|
51
51
|
* @protected
|
|
@@ -74,7 +74,7 @@ export declare class Fragment<T extends Options = Options> extends Reactive {
|
|
|
74
74
|
* @param data {*} additional data
|
|
75
75
|
*/
|
|
76
76
|
preinit(app: AppNode, parent: Fragment, data?: unknown): void;
|
|
77
|
-
init():
|
|
77
|
+
init(): T['return'];
|
|
78
78
|
protected compose(input: T): void;
|
|
79
79
|
/** To be overloaded: ready event handler */
|
|
80
80
|
ready(): void;
|
|
@@ -119,7 +119,7 @@ export declare class Fragment<T extends Options = Options> extends Reactive {
|
|
|
119
119
|
* @param node {Fragment} vasille element to insert
|
|
120
120
|
* @param callback {function($ : *)}
|
|
121
121
|
*/
|
|
122
|
-
create<T extends Fragment>(node: T, callback?: T['input']['slot']):
|
|
122
|
+
create<T extends Fragment>(node: T, callback?: T['input']['slot']): T['input']['return'];
|
|
123
123
|
/**
|
|
124
124
|
* Defines an if node
|
|
125
125
|
* @param cond {IValue} condition
|
|
@@ -317,6 +317,7 @@ export declare class Tag<K extends keyof AcceptedTagsMap> extends INode<TagOptio
|
|
|
317
317
|
*/
|
|
318
318
|
export declare class Extension<T extends TagOptions<any> = TagOptions<any>> extends INode<T> {
|
|
319
319
|
preinit(app: AppNode, parent: Fragment): void;
|
|
320
|
+
extend(options: T): void;
|
|
320
321
|
$destroy(): void;
|
|
321
322
|
}
|
|
322
323
|
/**
|
package/types/node/watch.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Fragment } from "./node";
|
|
2
2
|
import { IValue } from "../core/ivalue";
|
|
3
|
-
import {
|
|
4
|
-
interface WatchOptions<T> extends
|
|
3
|
+
import { FragmentOptions } from "../functional/options";
|
|
4
|
+
interface WatchOptions<T> extends FragmentOptions {
|
|
5
5
|
model: IValue<T>;
|
|
6
6
|
slot?: (node: Fragment, value: T) => void;
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Fragment, INodePrivate } from "../node/node";
|
|
2
|
-
import {
|
|
2
|
+
import { FragmentOptions } from "../functional/options";
|
|
3
3
|
/**
|
|
4
4
|
* Private part of repeat node
|
|
5
5
|
* @class RepeatNodePrivate
|
|
@@ -14,7 +14,7 @@ export declare class RepeatNodePrivate<IdT> extends INodePrivate {
|
|
|
14
14
|
constructor();
|
|
15
15
|
$destroy(): void;
|
|
16
16
|
}
|
|
17
|
-
export interface RNO<T, IdT> extends
|
|
17
|
+
export interface RNO<T, IdT> extends FragmentOptions {
|
|
18
18
|
slot?: (node: Fragment, value: T, index: IdT) => void;
|
|
19
19
|
}
|
|
20
20
|
/**
|
package/lib/core/executor.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { internalError, notOverwritten } from "./errors";
|
|
2
|
-
/**
|
|
3
|
-
* Represents an executor unit interface
|
|
4
|
-
* @class Executor
|
|
5
|
-
*/
|
|
6
|
-
export class Executor {
|
|
7
|
-
/**
|
|
8
|
-
* Adds a CSS class
|
|
9
|
-
* @param el {Element} element to manipulate
|
|
10
|
-
* @param cl {string} class to be added
|
|
11
|
-
*/
|
|
12
|
-
addClass(el, cl) {
|
|
13
|
-
throw notOverwritten();
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Removes a CSS class
|
|
17
|
-
* @param el {Element} element to manipulate
|
|
18
|
-
* @param cl {string} class to be removed
|
|
19
|
-
*/
|
|
20
|
-
removeClass(el, cl) {
|
|
21
|
-
throw notOverwritten();
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Sets a tag attribute
|
|
25
|
-
* @param el {Element} element to manipulate
|
|
26
|
-
* @param name {string} name of attribute
|
|
27
|
-
* @param value {string} value of attribute
|
|
28
|
-
*/
|
|
29
|
-
setAttribute(el, name, value) {
|
|
30
|
-
throw notOverwritten();
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Removes a tag attribute
|
|
34
|
-
* @param el {Element} element to manipulate
|
|
35
|
-
* @param name {string} name of attribute
|
|
36
|
-
*/
|
|
37
|
-
removeAttribute(el, name) {
|
|
38
|
-
throw notOverwritten();
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Sets a style attribute
|
|
42
|
-
* @param el {HTMLElement} element to manipulate
|
|
43
|
-
* @param prop {string} property name
|
|
44
|
-
* @param value {string} property value
|
|
45
|
-
*/
|
|
46
|
-
setStyle(el, prop, value) {
|
|
47
|
-
throw notOverwritten();
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Inserts a child before target
|
|
51
|
-
* @param target {Element} target element
|
|
52
|
-
* @param child {Node} element to insert before
|
|
53
|
-
*/
|
|
54
|
-
insertBefore(target, child) {
|
|
55
|
-
throw notOverwritten();
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Appends a child to element
|
|
59
|
-
* @param el {Element} element
|
|
60
|
-
* @param child {Node} child to be inserted
|
|
61
|
-
*/
|
|
62
|
-
appendChild(el, child) {
|
|
63
|
-
throw notOverwritten();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Calls a call-back function
|
|
67
|
-
* @param cb {function} call-back function
|
|
68
|
-
*/
|
|
69
|
-
callCallback(cb) {
|
|
70
|
-
throw notOverwritten();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Executor which execute any commands immediately
|
|
75
|
-
* @class InstantExecutor
|
|
76
|
-
* @extends Executor
|
|
77
|
-
*/
|
|
78
|
-
export class InstantExecutor extends Executor {
|
|
79
|
-
addClass(el, cl) {
|
|
80
|
-
el.classList.add(cl);
|
|
81
|
-
}
|
|
82
|
-
removeClass(el, cl) {
|
|
83
|
-
el.classList.remove(cl);
|
|
84
|
-
}
|
|
85
|
-
setAttribute(el, name, value) {
|
|
86
|
-
el.setAttribute(name, value);
|
|
87
|
-
}
|
|
88
|
-
removeAttribute(el, name) {
|
|
89
|
-
el.removeAttribute(name);
|
|
90
|
-
}
|
|
91
|
-
setStyle(el, prop, value) {
|
|
92
|
-
el.style.setProperty(prop, value);
|
|
93
|
-
}
|
|
94
|
-
insertBefore(target, child) {
|
|
95
|
-
const parent = target.parentNode;
|
|
96
|
-
if (!parent) {
|
|
97
|
-
throw internalError('element don\'t have a parent node');
|
|
98
|
-
}
|
|
99
|
-
parent.insertBefore(child, target);
|
|
100
|
-
}
|
|
101
|
-
appendChild(el, child) {
|
|
102
|
-
el.appendChild(child);
|
|
103
|
-
}
|
|
104
|
-
callCallback(cb) {
|
|
105
|
-
cb();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Executor which execute any commands over timeout
|
|
110
|
-
* @class TimeoutExecutor
|
|
111
|
-
* @extends InstantExecutor
|
|
112
|
-
*/
|
|
113
|
-
export class TimeoutExecutor extends InstantExecutor {
|
|
114
|
-
addClass(el, cl) {
|
|
115
|
-
setTimeout(() => {
|
|
116
|
-
super.addClass(el, cl);
|
|
117
|
-
}, 0);
|
|
118
|
-
}
|
|
119
|
-
removeClass(el, cl) {
|
|
120
|
-
setTimeout(() => {
|
|
121
|
-
super.removeClass(el, cl);
|
|
122
|
-
}, 0);
|
|
123
|
-
}
|
|
124
|
-
setAttribute(el, name, value) {
|
|
125
|
-
setTimeout(() => {
|
|
126
|
-
super.setAttribute(el, name, value);
|
|
127
|
-
}, 0);
|
|
128
|
-
}
|
|
129
|
-
removeAttribute(el, name) {
|
|
130
|
-
setTimeout(() => {
|
|
131
|
-
super.removeAttribute(el, name);
|
|
132
|
-
}, 0);
|
|
133
|
-
}
|
|
134
|
-
setStyle(el, prop, value) {
|
|
135
|
-
setTimeout(() => {
|
|
136
|
-
super.setStyle(el, prop, value);
|
|
137
|
-
}, 0);
|
|
138
|
-
}
|
|
139
|
-
insertBefore(target, child) {
|
|
140
|
-
setTimeout(() => {
|
|
141
|
-
super.insertBefore(target, child);
|
|
142
|
-
}, 0);
|
|
143
|
-
}
|
|
144
|
-
appendChild(el, child) {
|
|
145
|
-
setTimeout(() => {
|
|
146
|
-
super.appendChild(el, child);
|
|
147
|
-
}, 0);
|
|
148
|
-
}
|
|
149
|
-
callCallback(cb) {
|
|
150
|
-
setTimeout(cb, 0);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
export const instantExecutor = new InstantExecutor();
|
|
154
|
-
export const timeoutExecutor = new TimeoutExecutor();
|
package/lib/core/signal.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Signal is an event generator
|
|
3
|
-
* @class Signal
|
|
4
|
-
*/
|
|
5
|
-
export class Signal {
|
|
6
|
-
constructor() {
|
|
7
|
-
/**
|
|
8
|
-
* Handler of event
|
|
9
|
-
* @type {Set}
|
|
10
|
-
* @private
|
|
11
|
-
*/
|
|
12
|
-
this.handlers = new Set;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Emit event
|
|
16
|
-
* @param a1 {*} argument
|
|
17
|
-
* @param a2 {*} argument
|
|
18
|
-
* @param a3 {*} argument
|
|
19
|
-
* @param a4 {*} argument
|
|
20
|
-
* @param a5 {*} argument
|
|
21
|
-
* @param a6 {*} argument
|
|
22
|
-
* @param a7 {*} argument
|
|
23
|
-
* @param a8 {*} argument
|
|
24
|
-
* @param a9 {*} argument
|
|
25
|
-
*/
|
|
26
|
-
emit(a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
|
27
|
-
this.handlers.forEach(handler => {
|
|
28
|
-
try {
|
|
29
|
-
handler(a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
console.error(`Vasille.js: Handler throw exception: `, e);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Subscribe to event
|
|
38
|
-
* @param func {function} handler
|
|
39
|
-
*/
|
|
40
|
-
subscribe(func) {
|
|
41
|
-
this.handlers.add(func);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Unsubscribe from event
|
|
45
|
-
* @param func {function} handler
|
|
46
|
-
*/
|
|
47
|
-
unsubscribe(func) {
|
|
48
|
-
this.handlers.delete(func);
|
|
49
|
-
}
|
|
50
|
-
}
|
package/lib/core/slot.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Component slot
|
|
3
|
-
* @class Slot
|
|
4
|
-
*/
|
|
5
|
-
export class Slot {
|
|
6
|
-
/**
|
|
7
|
-
* Sets the runner
|
|
8
|
-
* @param func {function} the function to run
|
|
9
|
-
*/
|
|
10
|
-
insert(func) {
|
|
11
|
-
this.runner = func;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @param a0 {Fragment} node to paste content
|
|
15
|
-
* @param a1 {*} 1st argument
|
|
16
|
-
* @param a2 {*} 2nd argument
|
|
17
|
-
* @param a3 {*} 3rd argument
|
|
18
|
-
* @param a4 {*} 4th argument
|
|
19
|
-
* @param a5 {*} 5th argument
|
|
20
|
-
* @param a6 {*} 6th argument
|
|
21
|
-
* @param a7 {*} 7th argument
|
|
22
|
-
* @param a8 {*} 8th argument
|
|
23
|
-
* @param a9 {*} 9th argument
|
|
24
|
-
*/
|
|
25
|
-
release(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
|
26
|
-
if (this.runner) {
|
|
27
|
-
this.runner(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Predefine a handler for a slot
|
|
32
|
-
* @param func {function(node : Fragment)} Function to run if no handler specified
|
|
33
|
-
* @param a0 {Fragment} node to paste content
|
|
34
|
-
* @param a1 {*} 1st argument
|
|
35
|
-
* @param a2 {*} 2nd argument
|
|
36
|
-
* @param a3 {*} 3rd argument
|
|
37
|
-
* @param a4 {*} 4th argument
|
|
38
|
-
* @param a5 {*} 5th argument
|
|
39
|
-
* @param a6 {*} 6th argument
|
|
40
|
-
* @param a7 {*} 7th argument
|
|
41
|
-
* @param a8 {*} 8th argument
|
|
42
|
-
* @param a9 {*} 9th argument
|
|
43
|
-
*/
|
|
44
|
-
predefine(func, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) {
|
|
45
|
-
(this.runner || func)(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Fragment } from "../node/node";
|
|
2
|
-
import { current } from "../core/core";
|
|
3
|
-
import { userError } from "../core/errors";
|
|
4
|
-
export function text(text) {
|
|
5
|
-
if (!(current instanceof Fragment))
|
|
6
|
-
throw userError('missing parent node', 'out-of-context');
|
|
7
|
-
;
|
|
8
|
-
current.text(text);
|
|
9
|
-
}
|
|
10
|
-
export function debug(text) {
|
|
11
|
-
if (!(current instanceof Fragment))
|
|
12
|
-
throw userError('missing parent node', 'out-of-context');
|
|
13
|
-
current.debug(text);
|
|
14
|
-
}
|
|
15
|
-
export function predefine(slot, predefined) {
|
|
16
|
-
return slot || predefined;
|
|
17
|
-
}
|
package/lib/functional/merge.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { IValue } from "../core/ivalue";
|
|
2
|
-
export function merge(main, ...targets) {
|
|
3
|
-
function refactorClass(obj) {
|
|
4
|
-
if (Array.isArray(obj.class)) {
|
|
5
|
-
const out = {
|
|
6
|
-
$: []
|
|
7
|
-
};
|
|
8
|
-
obj.class.forEach(item => {
|
|
9
|
-
if (item instanceof IValue) {
|
|
10
|
-
out.$.push(item);
|
|
11
|
-
}
|
|
12
|
-
else if (typeof item === 'string') {
|
|
13
|
-
out[item] = true;
|
|
14
|
-
}
|
|
15
|
-
else if (typeof item === 'object') {
|
|
16
|
-
Object.assign(out, item);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
obj.class = out;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
refactorClass(main);
|
|
23
|
-
targets.forEach(target => {
|
|
24
|
-
Reflect.ownKeys(target).forEach((prop) => {
|
|
25
|
-
if (!Reflect.has(main, prop)) {
|
|
26
|
-
main[prop] = target[prop];
|
|
27
|
-
}
|
|
28
|
-
else if (typeof main[prop] === 'object' && typeof target[prop] === 'object') {
|
|
29
|
-
if (prop === 'class') {
|
|
30
|
-
refactorClass(target);
|
|
31
|
-
}
|
|
32
|
-
if (prop === '$' && Array.isArray(main[prop]) && Array.isArray(target[prop])) {
|
|
33
|
-
main.$.push(...target.$);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
merge(main[prop], target[prop]);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
package/lib/functional/models.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ArrayModel } from "../models/array-model";
|
|
2
|
-
import { MapModel } from "../models/map-model";
|
|
3
|
-
import { SetModel } from "../models/set-model";
|
|
4
|
-
import { ObjectModel } from "../models/object-model";
|
|
5
|
-
import { current } from "../core/core";
|
|
6
|
-
import { userError } from "../core/errors";
|
|
7
|
-
export function arrayModel(arr = []) {
|
|
8
|
-
if (!current)
|
|
9
|
-
throw userError('missing parent node', 'out-of-context');
|
|
10
|
-
return current.register(new ArrayModel(arr)).proxy();
|
|
11
|
-
}
|
|
12
|
-
export function mapModel(map = []) {
|
|
13
|
-
if (!current)
|
|
14
|
-
throw userError('missing parent node', 'out-of-context');
|
|
15
|
-
return current.register(new MapModel(map));
|
|
16
|
-
}
|
|
17
|
-
export function setModel(arr = []) {
|
|
18
|
-
if (!current)
|
|
19
|
-
throw userError('missing parent node', 'out-of-context');
|
|
20
|
-
return current.register(new SetModel(arr));
|
|
21
|
-
}
|
|
22
|
-
export function objectModel(obj = {}) {
|
|
23
|
-
if (!current)
|
|
24
|
-
throw userError('missing parent node', 'out-of-context');
|
|
25
|
-
return current.register(new ObjectModel(obj));
|
|
26
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { IValue } from "../core/ivalue";
|
|
2
|
-
import { Pointer } from "../value/pointer";
|
|
3
|
-
import { current } from "../core/core";
|
|
4
|
-
export function ref(value) {
|
|
5
|
-
const ref = current.ref(value);
|
|
6
|
-
return [ref, (value) => ref.$ = value];
|
|
7
|
-
}
|
|
8
|
-
export function mirror(value) {
|
|
9
|
-
return current.mirror(value);
|
|
10
|
-
}
|
|
11
|
-
export function forward(value) {
|
|
12
|
-
return current.forward(value);
|
|
13
|
-
}
|
|
14
|
-
export function point(value) {
|
|
15
|
-
return current.point(value);
|
|
16
|
-
}
|
|
17
|
-
export function expr(func, ...values) {
|
|
18
|
-
return current.expr(func, ...values);
|
|
19
|
-
}
|
|
20
|
-
export function watch(func, ...values) {
|
|
21
|
-
current.watch(func, ...values);
|
|
22
|
-
}
|
|
23
|
-
export function valueOf(value) {
|
|
24
|
-
return value.$;
|
|
25
|
-
}
|
|
26
|
-
export function setValue(ref, value) {
|
|
27
|
-
if (ref instanceof Pointer && value instanceof IValue) {
|
|
28
|
-
ref.$$ = value;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
ref.$ = value instanceof IValue ? value.$ : value;
|
|
32
|
-
}
|
|
33
|
-
}
|
package/lib/functional/stack.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
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/node/interceptor.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Fragment } from "./node";
|
|
2
|
-
import { Destroyable } from "../core/destroyable";
|
|
3
|
-
import { Signal } from "../core/signal";
|
|
4
|
-
import { Slot } from "../core/slot";
|
|
5
|
-
/**
|
|
6
|
-
* Interceptor is designed to connect signals & methods of children elements
|
|
7
|
-
* @class Interceptor
|
|
8
|
-
* @extends Destroyable
|
|
9
|
-
*/
|
|
10
|
-
export class Interceptor extends Destroyable {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(...arguments);
|
|
13
|
-
/**
|
|
14
|
-
* Set of signals
|
|
15
|
-
* @type Set
|
|
16
|
-
*/
|
|
17
|
-
this.signals = new Set;
|
|
18
|
-
/**
|
|
19
|
-
* Set of handlers
|
|
20
|
-
* @type Set
|
|
21
|
-
*/
|
|
22
|
-
this.handlers = new Set;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Connect a signal or a handler
|
|
26
|
-
* @param thing {Signal | function}
|
|
27
|
-
*/
|
|
28
|
-
connect(thing) {
|
|
29
|
-
// interceptor will connect signals and handlers together
|
|
30
|
-
if (thing instanceof Signal) {
|
|
31
|
-
this.handlers.forEach(handler => {
|
|
32
|
-
thing.subscribe(handler);
|
|
33
|
-
});
|
|
34
|
-
this.signals.add(thing);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
this.signals.forEach(signal => {
|
|
38
|
-
signal.subscribe(thing);
|
|
39
|
-
});
|
|
40
|
-
this.handlers.add(thing);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Disconnect a handler from signals
|
|
45
|
-
* @param handler {function}
|
|
46
|
-
*/
|
|
47
|
-
disconnect(handler) {
|
|
48
|
-
this.signals.forEach(signal => {
|
|
49
|
-
signal.unsubscribe(handler);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
destroy() {
|
|
53
|
-
super.destroy();
|
|
54
|
-
this.signals.forEach(signal => {
|
|
55
|
-
this.handlers.forEach(handler => {
|
|
56
|
-
signal.unsubscribe(handler);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Interceptor node to implement directly to vasille DOM
|
|
63
|
-
* @class InterceptorNode
|
|
64
|
-
* @extends Extension
|
|
65
|
-
*/
|
|
66
|
-
export class InterceptorNode extends Fragment {
|
|
67
|
-
constructor() {
|
|
68
|
-
super(...arguments);
|
|
69
|
-
/**
|
|
70
|
-
* Internal interceptor
|
|
71
|
-
* @type Interceptor
|
|
72
|
-
*/
|
|
73
|
-
this.interceptor = new Interceptor;
|
|
74
|
-
/**
|
|
75
|
-
* The default slot of node
|
|
76
|
-
* @type Slot
|
|
77
|
-
*/
|
|
78
|
-
this.slot = new Slot;
|
|
79
|
-
}
|
|
80
|
-
compose() {
|
|
81
|
-
this.slot.release(this, this.interceptor);
|
|
82
|
-
}
|
|
83
|
-
}
|
package/lib/v/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { debug, text } from "../functional/components";
|
|
2
|
-
import { arrayModel, mapModel, objectModel, setModel } from "../functional/models";
|
|
3
|
-
import { expr, forward, mirror, point, ref, setValue, valueOf, watch } from "../functional/reactivity";
|
|
4
|
-
import { app, component, create, extension, fragment, tag, vx } from "../functional/stack";
|
|
5
|
-
import { current } from "../core/core";
|
|
6
|
-
import { Reference } from "../value/reference";
|
|
7
|
-
import { merge } from "../functional/merge";
|
|
8
|
-
export { debug, arrayModel, mapModel, objectModel, setModel, expr, forward, mirror, point, ref, setValue, valueOf, watch };
|
|
9
|
-
export const v = Object.assign(Object.assign({ ref(value) {
|
|
10
|
-
return current.ref(value);
|
|
11
|
-
}, expr: expr, of: valueOf, sv: setValue, alwaysFalse: new Reference(false), app,
|
|
12
|
-
component,
|
|
13
|
-
fragment,
|
|
14
|
-
extension,
|
|
15
|
-
text,
|
|
16
|
-
tag,
|
|
17
|
-
create }, vx), { merge,
|
|
18
|
-
destructor() {
|
|
19
|
-
return current.$destroy.bind(current);
|
|
20
|
-
},
|
|
21
|
-
runOnDestroy(callback) {
|
|
22
|
-
current.runOnDestroy(callback);
|
|
23
|
-
} });
|