vasille 2.3.8 → 3.0.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 +122 -0
- package/lib/binding/attribute.js +4 -5
- package/lib/binding/binding.js +4 -5
- package/lib/binding/class.js +2 -4
- package/lib/binding/style.js +12 -4
- package/lib/core/config.js +3 -0
- package/lib/core/core.js +39 -177
- package/lib/core/destroyable.js +1 -36
- package/lib/core/ivalue.js +6 -49
- package/lib/functional/safety.js +7 -0
- package/lib/index.js +7 -8
- package/lib/models/array-model.js +40 -107
- package/lib/models/listener.js +16 -80
- package/lib/models/map-model.js +6 -13
- package/lib/models/object-model.js +6 -6
- package/lib/models/set-model.js +5 -12
- package/lib/node/app.js +8 -27
- package/lib/node/node.js +294 -524
- package/lib/node/watch.js +10 -8
- package/lib/tsconfig-build.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/value/expression.js +16 -41
- package/lib/value/mirror.js +9 -23
- package/lib/value/pointer.js +64 -16
- package/lib/value/reference.js +24 -29
- package/lib/views/array-view.js +5 -6
- package/lib/views/base-view.js +14 -26
- package/lib/views/map-view.js +4 -5
- package/lib/views/repeat-node.js +17 -34
- package/lib/views/set-view.js +7 -5
- package/lib-node/binding/attribute.js +4 -5
- package/lib-node/binding/binding.js +4 -5
- package/lib-node/binding/class.js +2 -4
- package/lib-node/binding/style.js +13 -4
- package/lib-node/core/config.js +6 -0
- package/lib-node/core/core.js +39 -180
- package/lib-node/core/destroyable.js +1 -36
- package/lib-node/core/ivalue.js +7 -51
- package/lib-node/functional/safety.js +12 -0
- package/lib-node/index.js +7 -12
- package/lib-node/models/array-model.js +41 -107
- package/lib-node/models/listener.js +16 -80
- package/lib-node/models/map-model.js +6 -13
- package/lib-node/models/object-model.js +6 -6
- package/lib-node/models/set-model.js +5 -12
- package/lib-node/node/app.js +8 -28
- package/lib-node/node/node.js +294 -529
- package/lib-node/node/watch.js +10 -8
- package/lib-node/tsconfig-build-node.tsbuildinfo +1 -1
- package/lib-node/value/expression.js +16 -41
- package/lib-node/value/mirror.js +9 -23
- package/lib-node/value/pointer.js +66 -17
- package/lib-node/value/reference.js +24 -29
- package/lib-node/views/array-view.js +5 -6
- package/lib-node/views/base-view.js +14 -27
- package/lib-node/views/map-view.js +4 -5
- package/lib-node/views/repeat-node.js +17 -35
- package/lib-node/views/set-view.js +7 -5
- package/package.json +4 -4
- package/types/binding/attribute.d.ts +2 -2
- package/types/binding/binding.d.ts +1 -1
- package/types/binding/style.d.ts +3 -2
- package/types/core/config.d.ts +3 -0
- package/types/core/core.d.ts +18 -93
- package/types/core/destroyable.d.ts +11 -6
- package/types/core/ivalue.d.ts +7 -24
- package/types/functional/options.d.ts +7 -22
- package/types/functional/safety.d.ts +2 -0
- package/types/index.d.ts +8 -10
- package/types/models/array-model.d.ts +6 -55
- package/types/models/listener.d.ts +0 -26
- package/types/models/map-model.d.ts +3 -4
- package/types/models/model.d.ts +2 -9
- package/types/models/set-model.d.ts +1 -2
- package/types/node/app.d.ts +7 -25
- package/types/node/node.d.ts +105 -222
- package/types/node/watch.d.ts +4 -5
- package/types/spec/html.d.ts +231 -231
- package/types/spec/svg.d.ts +166 -166
- package/types/tsconfig-types.tsbuildinfo +1 -1
- package/types/value/expression.d.ts +5 -7
- package/types/value/mirror.d.ts +4 -6
- package/types/value/pointer.d.ts +26 -9
- package/types/value/reference.d.ts +6 -7
- package/types/views/array-view.d.ts +3 -3
- package/types/views/base-view.d.ts +15 -23
- package/types/views/map-view.d.ts +2 -2
- package/types/views/repeat-node.d.ts +9 -23
- package/types/views/set-view.d.ts +3 -2
- package/cdn/es2015.js +0 -2480
- package/flow-typed/vasille.js +0 -2613
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Vasille
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
`Vasille Web` is a front-end framework, which is developed to provide the best `developer experience` ever. **Our goal is to keep is as simple as possible.** Developing web applications using Vasille must be *as fast as possible*.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/vasille)
|
|
8
|
+
|
|
9
|
+
## Table of content
|
|
10
|
+
|
|
11
|
+
* [Installation](#installation)
|
|
12
|
+
* [How to use Vasille](#how-to-use-vasille)
|
|
13
|
+
* [How SAFE is Vasille](#how-safe-is-vasille)
|
|
14
|
+
* [How SIMPLE is Vasille](#how-simple-is-vasille)
|
|
15
|
+
* [How POWERFUL is Vasille](#how-powerful-is-vasille)
|
|
16
|
+
* [Road Map](#road-map)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
<hr>
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npm install vasille-web --save
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## How to use Vasille
|
|
28
|
+
|
|
29
|
+
Create an app from a template
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
$ npx create vasille
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Alternative method to create a TypeScript app.
|
|
36
|
+
```bash
|
|
37
|
+
$ npx degit vasille-js/example-typescript my-project
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Alternative method to create a JavaScript app.
|
|
41
|
+
```bash
|
|
42
|
+
$ npx degit vasille-js/example-javascript my-project
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Full documentation:
|
|
46
|
+
* [Learn `Vasille` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v3/doc/V3-API.md)
|
|
47
|
+
|
|
48
|
+
### Examples
|
|
49
|
+
* [TypeScript Example](https://github.com/vasille-js/example-typescript)
|
|
50
|
+
* [JavaScript Example](https://github.com/vas[README.md](..%2Ftest%2Fmy-app%2FREADME.md)ille-js/example-javascript)
|
|
51
|
+
|
|
52
|
+
<hr>
|
|
53
|
+
|
|
54
|
+
## How SAFE is Vasille
|
|
55
|
+
|
|
56
|
+
The safe of your application is ensured by
|
|
57
|
+
* `100%` coverage of code by unit tests.
|
|
58
|
+
Each function, each branch is working as designed.
|
|
59
|
+
* OOP, DRY, KISS and SOLID principles are applied.
|
|
60
|
+
* `strong typing` makes your javascript/typescript code safe as C++ code.
|
|
61
|
+
All entities of `vasille` core library are strongly typed, including:
|
|
62
|
+
* data fields & properties.
|
|
63
|
+
* computed properties (function parameters & result).
|
|
64
|
+
* methods.
|
|
65
|
+
* events (defined handlers & event emit).
|
|
66
|
+
* DOM events & DOM operation (attributing, styling, etc.).
|
|
67
|
+
* slots of components.
|
|
68
|
+
* references to children.
|
|
69
|
+
* No asynchronous code, when the line of code is executed, the DOM and reactive things are already synced.
|
|
70
|
+
|
|
71
|
+
## How SIMPLE is Vasille
|
|
72
|
+
|
|
73
|
+
There is the "Hello World":
|
|
74
|
+
```typescript jsx
|
|
75
|
+
import { compose, mount } from "vasille-dx";
|
|
76
|
+
|
|
77
|
+
const App = compose(() => {
|
|
78
|
+
<p>Hello world</p>;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
mount(document.body, App, {});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## How POWERFUL is Vasille
|
|
85
|
+
|
|
86
|
+
All of these are supported:
|
|
87
|
+
* Components.
|
|
88
|
+
* Reactive values (observables).
|
|
89
|
+
* Inline computed values.
|
|
90
|
+
* Multiline computed values.
|
|
91
|
+
* HTML & SVG tags.
|
|
92
|
+
* Component custom slots.
|
|
93
|
+
* 2-way data binding in components.
|
|
94
|
+
* Logic block (if, else).
|
|
95
|
+
* Loops (array, map, set).
|
|
96
|
+
|
|
97
|
+
<hr>
|
|
98
|
+
|
|
99
|
+
## Road map
|
|
100
|
+
|
|
101
|
+
* [x] Update the `Vasille Core` library to version 3.0.
|
|
102
|
+
* [x] `100%` Test Coverage for core Library v3.
|
|
103
|
+
* [x] Develop the `Vasille JSX` library.
|
|
104
|
+
* [x] `100%` Test Coverage for the JSX library.
|
|
105
|
+
* [x] Develop the `Vasille Babel Plugin`.
|
|
106
|
+
* [ ] `100%` Test Coverage fot babel plugin.
|
|
107
|
+
* [ ] Add CSS support (define styles in components).
|
|
108
|
+
* [ ] Add custom `<input/>` components with 2-way value binding.
|
|
109
|
+
* [ ] Add router.
|
|
110
|
+
* [ ] Develop dev-tools extension for debugging.
|
|
111
|
+
* [ ] Develop a lot of libraries for the framework.
|
|
112
|
+
|
|
113
|
+
## Questions
|
|
114
|
+
|
|
115
|
+
If you have questions, feel free to contact the maintainer of the project:
|
|
116
|
+
|
|
117
|
+
* [Author's Email](mailto:vas.lixcode@gmail.com)
|
|
118
|
+
* [Author's Telegram](https://t.me/lixcode)
|
|
119
|
+
|
|
120
|
+
<hr>
|
|
121
|
+
|
|
122
|
+
**Made in Moldova** 🇲🇩
|
package/lib/binding/attribute.js
CHANGED
|
@@ -15,17 +15,16 @@ export class AttributeBinding extends Binding {
|
|
|
15
15
|
super(value);
|
|
16
16
|
this.init((value) => {
|
|
17
17
|
if (value) {
|
|
18
|
-
if (typeof value ===
|
|
19
|
-
node.
|
|
18
|
+
if (typeof value === "boolean") {
|
|
19
|
+
node.element.setAttribute(name, "");
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
22
|
-
node.
|
|
22
|
+
node.element.setAttribute(name, `${value}`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
-
node.
|
|
26
|
+
node.element.removeAttribute(name);
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
|
-
this.$seal();
|
|
30
29
|
}
|
|
31
30
|
}
|
package/lib/binding/binding.js
CHANGED
|
@@ -12,18 +12,17 @@ export class Binding extends Destroyable {
|
|
|
12
12
|
constructor(value) {
|
|
13
13
|
super();
|
|
14
14
|
this.binding = value;
|
|
15
|
-
this.$seal();
|
|
16
15
|
}
|
|
17
16
|
init(bounded) {
|
|
18
17
|
this.func = bounded;
|
|
19
|
-
this.binding
|
|
18
|
+
this.binding.on(this.func);
|
|
20
19
|
this.func(this.binding.$);
|
|
21
20
|
}
|
|
22
21
|
/**
|
|
23
22
|
* Just clear bindings
|
|
24
23
|
*/
|
|
25
|
-
|
|
26
|
-
this.binding
|
|
27
|
-
super
|
|
24
|
+
destroy() {
|
|
25
|
+
this.binding.off(this.func);
|
|
26
|
+
super.destroy();
|
|
28
27
|
}
|
|
29
28
|
}
|
package/lib/binding/class.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Binding } from "./binding";
|
|
2
2
|
function addClass(node, cl) {
|
|
3
|
-
node.
|
|
3
|
+
node.element.classList.add(cl);
|
|
4
4
|
}
|
|
5
5
|
function removeClass(node, cl) {
|
|
6
|
-
node.
|
|
6
|
+
node.element.classList.remove(cl);
|
|
7
7
|
}
|
|
8
8
|
export class StaticClassBinding extends Binding {
|
|
9
9
|
constructor(node, name, value) {
|
|
@@ -20,7 +20,6 @@ export class StaticClassBinding extends Binding {
|
|
|
20
20
|
this.current = value;
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
this.$seal();
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
export class DynamicalClassBinding extends Binding {
|
|
@@ -38,6 +37,5 @@ export class DynamicalClassBinding extends Binding {
|
|
|
38
37
|
this.current = value;
|
|
39
38
|
}
|
|
40
39
|
});
|
|
41
|
-
this.$seal();
|
|
42
40
|
}
|
|
43
41
|
}
|
package/lib/binding/style.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { Binding } from "./binding";
|
|
2
|
+
export function stringifyStyleValue(value) {
|
|
3
|
+
if (value instanceof Array) {
|
|
4
|
+
return value.map(item => `${item}px`).join(" ");
|
|
5
|
+
}
|
|
6
|
+
if (typeof value === "number") {
|
|
7
|
+
return `${value}px`;
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
2
11
|
/**
|
|
3
12
|
* Describes a style attribute binding
|
|
4
13
|
* @class StyleBinding
|
|
@@ -13,11 +22,10 @@ export class StyleBinding extends Binding {
|
|
|
13
22
|
*/
|
|
14
23
|
constructor(node, name, value) {
|
|
15
24
|
super(value);
|
|
16
|
-
this.init(
|
|
17
|
-
if (node.
|
|
18
|
-
node.
|
|
25
|
+
this.init(value => {
|
|
26
|
+
if (node.element instanceof HTMLElement) {
|
|
27
|
+
node.element.style.setProperty(name, stringifyStyleValue(value));
|
|
19
28
|
}
|
|
20
29
|
});
|
|
21
|
-
this.$seal();
|
|
22
30
|
}
|
|
23
31
|
}
|
package/lib/core/core.js
CHANGED
|
@@ -1,128 +1,63 @@
|
|
|
1
1
|
import { Destroyable } from "./destroyable.js";
|
|
2
|
-
import { notOverwritten, wrongBinding } from "./errors";
|
|
3
2
|
import { Expression } from "../value/expression";
|
|
4
3
|
import { Reference } from "../value/reference";
|
|
5
|
-
import { Pointer } from "../value/pointer";
|
|
6
|
-
import { Mirror } from "../value/mirror";
|
|
7
|
-
export let current = null;
|
|
8
|
-
const currentStack = [];
|
|
9
|
-
export function stack(node) {
|
|
10
|
-
currentStack.push(current);
|
|
11
|
-
current = node;
|
|
12
|
-
}
|
|
13
|
-
export function unstack() {
|
|
14
|
-
current = currentStack.pop();
|
|
15
|
-
}
|
|
4
|
+
import { OwningPointer, Pointer } from "../value/pointer";
|
|
16
5
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @class
|
|
6
|
+
* A reactive object
|
|
7
|
+
* @class Reactive
|
|
19
8
|
* @extends Destroyable
|
|
20
9
|
*/
|
|
21
|
-
export class
|
|
22
|
-
constructor() {
|
|
10
|
+
export class Reactive extends Destroyable {
|
|
11
|
+
constructor(input) {
|
|
23
12
|
super();
|
|
24
13
|
/**
|
|
25
14
|
* A list of user-defined values
|
|
26
15
|
* @type {Set}
|
|
27
16
|
*/
|
|
28
|
-
this.
|
|
17
|
+
this._watch = new Set();
|
|
29
18
|
/**
|
|
30
19
|
* A list of user-defined bindings
|
|
31
20
|
* @type {Set}
|
|
32
21
|
*/
|
|
33
|
-
this.bindings = new Set;
|
|
34
|
-
/**
|
|
35
|
-
* A list of user defined models
|
|
36
|
-
*/
|
|
37
|
-
this.models = new Set;
|
|
38
|
-
/**
|
|
39
|
-
* Reactivity switch state
|
|
40
|
-
* @type {boolean}
|
|
41
|
-
*/
|
|
42
|
-
this.enabled = true;
|
|
43
|
-
/**
|
|
44
|
-
* The frozen state of object
|
|
45
|
-
* @type {boolean}
|
|
46
|
-
*/
|
|
47
|
-
this.frozen = false;
|
|
48
|
-
this.$seal();
|
|
49
|
-
}
|
|
50
|
-
$destroy() {
|
|
51
|
-
this.watch.forEach(value => value.$destroy());
|
|
52
|
-
this.watch.clear();
|
|
53
|
-
this.bindings.forEach(binding => binding.$destroy());
|
|
54
|
-
this.bindings.clear();
|
|
55
|
-
this.models.forEach(model => model.disableReactivity());
|
|
56
|
-
this.models.clear();
|
|
57
|
-
this.freezeExpr && this.freezeExpr.$destroy();
|
|
58
|
-
this.onDestroy && this.onDestroy();
|
|
59
|
-
super.$destroy();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* A reactive object
|
|
64
|
-
* @class Reactive
|
|
65
|
-
* @extends Destroyable
|
|
66
|
-
*/
|
|
67
|
-
export class Reactive extends Destroyable {
|
|
68
|
-
constructor(input, $) {
|
|
69
|
-
super();
|
|
22
|
+
this.bindings = new Set();
|
|
70
23
|
this.input = input;
|
|
71
|
-
this.$ = $ || new ReactivePrivate;
|
|
72
|
-
this.$seal();
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Get parent node
|
|
76
|
-
*/
|
|
77
|
-
get parent() {
|
|
78
|
-
return this.$.parent;
|
|
79
24
|
}
|
|
80
25
|
/**
|
|
81
26
|
* Create a reference
|
|
82
27
|
* @param value {*} value to reference
|
|
83
28
|
*/
|
|
84
29
|
ref(value) {
|
|
85
|
-
const $ = this.$;
|
|
86
30
|
const ref = new Reference(value);
|
|
87
|
-
|
|
31
|
+
this._watch.add(ref);
|
|
88
32
|
return ref;
|
|
89
33
|
}
|
|
90
34
|
/**
|
|
91
|
-
* Create a
|
|
92
|
-
* @param value {IValue} value to
|
|
93
|
-
*/
|
|
94
|
-
mirror(value) {
|
|
95
|
-
const mirror = new Mirror(value, false);
|
|
96
|
-
this.$.watch.add(mirror);
|
|
97
|
-
return mirror;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Create a forward-only mirror
|
|
101
|
-
* @param value {IValue} value to mirror
|
|
35
|
+
* Create a forward-only pointer
|
|
36
|
+
* @param value {IValue} value to point
|
|
102
37
|
*/
|
|
103
38
|
forward(value) {
|
|
104
|
-
const mirror = new
|
|
105
|
-
this
|
|
39
|
+
const mirror = new Pointer(value);
|
|
40
|
+
this._watch.add(mirror);
|
|
106
41
|
return mirror;
|
|
107
42
|
}
|
|
108
43
|
/**
|
|
109
44
|
* Creates a pointer
|
|
110
45
|
* @param value {*} default value to point
|
|
111
|
-
* @param forwardOnly {boolean} forward only sync
|
|
112
46
|
*/
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
$.watch.add(pointer);
|
|
47
|
+
own(value) {
|
|
48
|
+
const pointer = new OwningPointer(value);
|
|
49
|
+
this._watch.add(pointer);
|
|
117
50
|
return pointer;
|
|
118
51
|
}
|
|
119
52
|
/**
|
|
120
|
-
* Register a model
|
|
121
|
-
* @param model
|
|
53
|
+
* Register a model/dependency
|
|
122
54
|
*/
|
|
123
|
-
register(
|
|
124
|
-
this
|
|
125
|
-
return
|
|
55
|
+
register(data) {
|
|
56
|
+
this.bindings.add(data);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
release(data) {
|
|
60
|
+
this.bindings.delete(data);
|
|
126
61
|
}
|
|
127
62
|
/**
|
|
128
63
|
* Creates a watcher
|
|
@@ -130,8 +65,7 @@ export class Reactive extends Destroyable {
|
|
|
130
65
|
* @param values
|
|
131
66
|
*/
|
|
132
67
|
watch(func, ...values) {
|
|
133
|
-
|
|
134
|
-
$.watch.add(new Expression(func, !this.$.frozen, ...values));
|
|
68
|
+
this._watch.add(new Expression(func, ...values));
|
|
135
69
|
}
|
|
136
70
|
/**
|
|
137
71
|
* Creates a computed value
|
|
@@ -140,96 +74,24 @@ export class Reactive extends Destroyable {
|
|
|
140
74
|
* @return {IValue} the created ivalue
|
|
141
75
|
*/
|
|
142
76
|
expr(func, ...values) {
|
|
143
|
-
const res = new Expression(func,
|
|
144
|
-
|
|
145
|
-
$.watch.add(res);
|
|
77
|
+
const res = new Expression(func, ...values);
|
|
78
|
+
this._watch.add(res);
|
|
146
79
|
return res;
|
|
147
80
|
}
|
|
148
|
-
/**
|
|
149
|
-
* Enable reactivity of fields
|
|
150
|
-
*/
|
|
151
|
-
enable() {
|
|
152
|
-
const $ = this.$;
|
|
153
|
-
if (!$.enabled) {
|
|
154
|
-
$.watch.forEach(watcher => {
|
|
155
|
-
watcher.$enable();
|
|
156
|
-
});
|
|
157
|
-
$.models.forEach(model => {
|
|
158
|
-
model.enableReactivity();
|
|
159
|
-
});
|
|
160
|
-
$.enabled = true;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Disable reactivity of fields
|
|
165
|
-
*/
|
|
166
|
-
disable() {
|
|
167
|
-
const $ = this.$;
|
|
168
|
-
if ($.enabled) {
|
|
169
|
-
$.watch.forEach(watcher => {
|
|
170
|
-
watcher.$disable();
|
|
171
|
-
});
|
|
172
|
-
$.models.forEach(model => {
|
|
173
|
-
model.disableReactivity();
|
|
174
|
-
});
|
|
175
|
-
$.enabled = false;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Disable/Enable reactivity of object fields with feedback
|
|
180
|
-
* @param cond {IValue} show condition
|
|
181
|
-
* @param onOff {function} on show feedback
|
|
182
|
-
* @param onOn {function} on hide feedback
|
|
183
|
-
*/
|
|
184
|
-
bindAlive(cond, onOff, onOn) {
|
|
185
|
-
const $ = this.$;
|
|
186
|
-
if ($.freezeExpr) {
|
|
187
|
-
throw wrongBinding("this component already have a freeze state");
|
|
188
|
-
}
|
|
189
|
-
if ($.watch.has(cond)) {
|
|
190
|
-
throw wrongBinding("freeze state must be bound to an external component");
|
|
191
|
-
}
|
|
192
|
-
$.freezeExpr = new Expression((cond) => {
|
|
193
|
-
$.frozen = !cond;
|
|
194
|
-
if (cond) {
|
|
195
|
-
onOn === null || onOn === void 0 ? void 0 : onOn();
|
|
196
|
-
this.enable();
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
onOff === null || onOff === void 0 ? void 0 : onOff();
|
|
200
|
-
this.disable();
|
|
201
|
-
}
|
|
202
|
-
}, true, cond);
|
|
203
|
-
return this;
|
|
204
|
-
}
|
|
205
|
-
init() {
|
|
206
|
-
this.applyOptions(this.input);
|
|
207
|
-
return this.compose(this.input);
|
|
208
|
-
}
|
|
209
|
-
applyOptions(input) {
|
|
210
|
-
// empty
|
|
211
|
-
}
|
|
212
|
-
applyOptionsNow() {
|
|
213
|
-
this.applyOptions(this.input);
|
|
214
|
-
}
|
|
215
|
-
compose(input) {
|
|
216
|
-
throw notOverwritten();
|
|
217
|
-
}
|
|
218
|
-
composeNow() {
|
|
219
|
-
return this.compose(this.input);
|
|
220
|
-
}
|
|
221
|
-
runFunctional(f, ...args) {
|
|
222
|
-
stack(this);
|
|
223
|
-
const result = f(...args);
|
|
224
|
-
unstack();
|
|
225
|
-
return result;
|
|
226
|
-
}
|
|
227
81
|
runOnDestroy(func) {
|
|
228
|
-
this
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this
|
|
233
|
-
|
|
82
|
+
if (this.onDestroy) {
|
|
83
|
+
console.warn(new Error("You rewrite onDestroy existing handler"));
|
|
84
|
+
console.log(this.onDestroy);
|
|
85
|
+
}
|
|
86
|
+
this.onDestroy = func;
|
|
87
|
+
}
|
|
88
|
+
destroy() {
|
|
89
|
+
var _a;
|
|
90
|
+
super.destroy();
|
|
91
|
+
this._watch.forEach(value => value.destroy());
|
|
92
|
+
this._watch.clear();
|
|
93
|
+
this.bindings.forEach(binding => binding.destroy());
|
|
94
|
+
this.bindings.clear();
|
|
95
|
+
(_a = this.onDestroy) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
234
96
|
}
|
|
235
97
|
}
|
package/lib/core/destroyable.js
CHANGED
|
@@ -3,43 +3,8 @@
|
|
|
3
3
|
* @class Destroyable
|
|
4
4
|
*/
|
|
5
5
|
export class Destroyable {
|
|
6
|
-
/**
|
|
7
|
-
* Make object fields non configurable
|
|
8
|
-
* @protected
|
|
9
|
-
*/
|
|
10
|
-
$seal() {
|
|
11
|
-
const $ = this;
|
|
12
|
-
Object.keys($).forEach(i => {
|
|
13
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
14
|
-
if (this.hasOwnProperty(i)) {
|
|
15
|
-
const config = Object.getOwnPropertyDescriptor($, i);
|
|
16
|
-
if (config.configurable) {
|
|
17
|
-
let descriptor;
|
|
18
|
-
if (config.set || config.get) {
|
|
19
|
-
descriptor = {
|
|
20
|
-
configurable: false,
|
|
21
|
-
get: config.get,
|
|
22
|
-
set: config.set,
|
|
23
|
-
enumerable: config.enumerable
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
descriptor = {
|
|
28
|
-
value: $[i],
|
|
29
|
-
configurable: false,
|
|
30
|
-
writable: config.writable,
|
|
31
|
-
enumerable: config.enumerable
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
Object.defineProperty($, i, descriptor);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
6
|
/**
|
|
40
7
|
* Garbage collector method
|
|
41
8
|
*/
|
|
42
|
-
|
|
43
|
-
// nothing here
|
|
44
|
-
}
|
|
9
|
+
destroy() { }
|
|
45
10
|
}
|
package/lib/core/ivalue.js
CHANGED
|
@@ -1,58 +1,15 @@
|
|
|
1
1
|
import { Destroyable } from "./destroyable.js";
|
|
2
|
-
import { notOverwritten } from "./errors";
|
|
3
|
-
export class Switchable extends Destroyable {
|
|
4
|
-
/**
|
|
5
|
-
* Enable update handlers triggering
|
|
6
|
-
*/
|
|
7
|
-
$enable() {
|
|
8
|
-
throw notOverwritten();
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* disable update handlers triggering
|
|
12
|
-
*/
|
|
13
|
-
$disable() {
|
|
14
|
-
throw notOverwritten();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
2
|
/**
|
|
18
3
|
* Interface which describes a value
|
|
19
4
|
* @class IValue
|
|
20
5
|
* @extends Destroyable
|
|
21
6
|
*/
|
|
22
|
-
export class IValue extends
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
26
|
-
constructor(isEnabled) {
|
|
27
|
-
super();
|
|
28
|
-
this.isEnabled = isEnabled;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Get the encapsulated value
|
|
32
|
-
* @return {*} the encapsulated value
|
|
33
|
-
*/
|
|
34
|
-
get $() {
|
|
35
|
-
throw notOverwritten();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Sets the encapsulated value
|
|
39
|
-
* @param value {*} value to encapsulate
|
|
40
|
-
*/
|
|
41
|
-
set $(value) {
|
|
42
|
-
throw notOverwritten();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Add a new handler to value change
|
|
46
|
-
* @param handler {function(value : *)} the handler to add
|
|
47
|
-
*/
|
|
48
|
-
$on(handler) {
|
|
49
|
-
throw notOverwritten();
|
|
7
|
+
export class IValue extends Destroyable {
|
|
8
|
+
toJSON() {
|
|
9
|
+
return this.$;
|
|
50
10
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
$off(handler) {
|
|
56
|
-
throw notOverwritten();
|
|
11
|
+
toString() {
|
|
12
|
+
var _a, _b;
|
|
13
|
+
return (_b = (_a = this.$) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "iValue<void>";
|
|
57
14
|
}
|
|
58
15
|
}
|
package/lib/index.js
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
+
import { config } from "./core/config";
|
|
1
2
|
import { Destroyable } from "./core/destroyable";
|
|
2
|
-
import {
|
|
3
|
+
import { Reactive } from "./core/core";
|
|
3
4
|
import { IValue } from "./core/ivalue";
|
|
4
|
-
import {
|
|
5
|
+
import { reportError, setErrorHandler } from "./functional/safety";
|
|
6
|
+
import { ArrayModel, proxyArrayModel } from "./models/array-model";
|
|
5
7
|
import { Listener } from "./models/listener";
|
|
6
8
|
import { MapModel } from "./models/map-model";
|
|
7
|
-
import { ObjectModel } from "./models/object-model";
|
|
8
9
|
import { SetModel } from "./models/set-model";
|
|
9
|
-
import { App,
|
|
10
|
-
import {
|
|
10
|
+
import { App, Portal } from "./node/app";
|
|
11
|
+
import { Extension, Fragment, INode, Tag } from "./node/node";
|
|
11
12
|
import { Expression } from "./value/expression";
|
|
12
|
-
import { Mirror } from "./value/mirror";
|
|
13
13
|
import { Pointer } from "./value/pointer";
|
|
14
14
|
import { Reference } from "./value/reference";
|
|
15
15
|
import { ArrayView } from "./views/array-view";
|
|
16
16
|
import { BaseView } from "./views/base-view";
|
|
17
17
|
import { MapView } from "./views/map-view";
|
|
18
|
-
import { ObjectView } from "./views/object-view";
|
|
19
18
|
import { SetView } from "./views/set-view";
|
|
20
19
|
import { Binding } from "./binding/binding";
|
|
21
20
|
import { userError } from "./core/errors";
|
|
22
21
|
import { Watch } from "./node/watch";
|
|
23
|
-
export { Destroyable, IValue, Reference,
|
|
22
|
+
export { Destroyable, IValue, Reference, Pointer, ArrayModel, proxyArrayModel, MapModel, SetModel, BaseView, Listener, ArrayView, MapView, SetView, Fragment, INode, Tag, Extension, App, Portal, Expression, Binding, Reactive, Watch, userError, config, setErrorHandler, reportError, };
|