vasille 2.3.9 → 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.
Files changed (91) hide show
  1. package/README.md +57 -155
  2. package/lib/binding/attribute.js +4 -5
  3. package/lib/binding/binding.js +4 -5
  4. package/lib/binding/class.js +2 -4
  5. package/lib/binding/style.js +12 -4
  6. package/lib/core/config.js +3 -0
  7. package/lib/core/core.js +39 -177
  8. package/lib/core/destroyable.js +1 -36
  9. package/lib/core/ivalue.js +6 -49
  10. package/lib/functional/safety.js +7 -0
  11. package/lib/index.js +7 -8
  12. package/lib/models/array-model.js +40 -107
  13. package/lib/models/listener.js +16 -80
  14. package/lib/models/map-model.js +6 -13
  15. package/lib/models/object-model.js +6 -6
  16. package/lib/models/set-model.js +5 -12
  17. package/lib/node/app.js +8 -27
  18. package/lib/node/node.js +294 -524
  19. package/lib/node/watch.js +10 -8
  20. package/lib/tsconfig-build.tsbuildinfo +1 -1
  21. package/lib/tsconfig.tsbuildinfo +1 -0
  22. package/lib/value/expression.js +16 -41
  23. package/lib/value/mirror.js +9 -23
  24. package/lib/value/pointer.js +64 -16
  25. package/lib/value/reference.js +24 -29
  26. package/lib/views/array-view.js +5 -6
  27. package/lib/views/base-view.js +14 -26
  28. package/lib/views/map-view.js +4 -5
  29. package/lib/views/repeat-node.js +17 -34
  30. package/lib/views/set-view.js +7 -5
  31. package/lib-node/binding/attribute.js +4 -5
  32. package/lib-node/binding/binding.js +4 -5
  33. package/lib-node/binding/class.js +2 -4
  34. package/lib-node/binding/style.js +13 -4
  35. package/lib-node/core/config.js +6 -0
  36. package/lib-node/core/core.js +39 -180
  37. package/lib-node/core/destroyable.js +1 -36
  38. package/lib-node/core/ivalue.js +7 -51
  39. package/lib-node/functional/safety.js +12 -0
  40. package/lib-node/index.js +7 -12
  41. package/lib-node/models/array-model.js +41 -107
  42. package/lib-node/models/listener.js +16 -80
  43. package/lib-node/models/map-model.js +6 -13
  44. package/lib-node/models/object-model.js +6 -6
  45. package/lib-node/models/set-model.js +5 -12
  46. package/lib-node/node/app.js +8 -28
  47. package/lib-node/node/node.js +294 -529
  48. package/lib-node/node/watch.js +10 -8
  49. package/lib-node/tsconfig-build-node.tsbuildinfo +1 -1
  50. package/lib-node/value/expression.js +16 -41
  51. package/lib-node/value/mirror.js +9 -23
  52. package/lib-node/value/pointer.js +66 -17
  53. package/lib-node/value/reference.js +24 -29
  54. package/lib-node/views/array-view.js +5 -6
  55. package/lib-node/views/base-view.js +14 -27
  56. package/lib-node/views/map-view.js +4 -5
  57. package/lib-node/views/repeat-node.js +17 -35
  58. package/lib-node/views/set-view.js +7 -5
  59. package/package.json +3 -4
  60. package/types/binding/attribute.d.ts +2 -2
  61. package/types/binding/binding.d.ts +1 -1
  62. package/types/binding/style.d.ts +3 -2
  63. package/types/core/config.d.ts +3 -0
  64. package/types/core/core.d.ts +18 -93
  65. package/types/core/destroyable.d.ts +11 -6
  66. package/types/core/ivalue.d.ts +7 -24
  67. package/types/functional/options.d.ts +7 -22
  68. package/types/functional/safety.d.ts +2 -0
  69. package/types/index.d.ts +8 -10
  70. package/types/models/array-model.d.ts +6 -55
  71. package/types/models/listener.d.ts +0 -26
  72. package/types/models/map-model.d.ts +3 -4
  73. package/types/models/model.d.ts +2 -9
  74. package/types/models/set-model.d.ts +1 -2
  75. package/types/node/app.d.ts +7 -25
  76. package/types/node/node.d.ts +105 -222
  77. package/types/node/watch.d.ts +4 -5
  78. package/types/spec/html.d.ts +231 -231
  79. package/types/spec/svg.d.ts +166 -166
  80. package/types/tsconfig-types.tsbuildinfo +1 -1
  81. package/types/value/expression.d.ts +5 -7
  82. package/types/value/mirror.d.ts +4 -6
  83. package/types/value/pointer.d.ts +26 -9
  84. package/types/value/reference.d.ts +6 -7
  85. package/types/views/array-view.d.ts +3 -3
  86. package/types/views/base-view.d.ts +15 -23
  87. package/types/views/map-view.d.ts +2 -2
  88. package/types/views/repeat-node.d.ts +9 -23
  89. package/types/views/set-view.d.ts +3 -2
  90. package/cdn/es2015.js +0 -2480
  91. package/flow-typed/vasille.js +0 -2613
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![Vasille.js logo](https://gitlab.com/vasille-js/vasille-js/-/raw/v2/doc/img/logo.png)
4
4
 
5
- `Vasille` core library is frontend solution for `safe`, `performant` & `powerful` applications.
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
6
 
7
7
  [![npm](https://img.shields.io/npm/v/vasille?style=flat-square)](https://www.npmjs.com/package/vasille)
8
8
 
@@ -11,9 +11,9 @@
11
11
  * [Installation](#installation)
12
12
  * [How to use Vasille](#how-to-use-vasille)
13
13
  * [How SAFE is Vasille](#how-safe-is-vasille)
14
- * [How SIMPLE is Vasille](#how-fast-is-vasille)
14
+ * [How SIMPLE is Vasille](#how-simple-is-vasille)
15
15
  * [How POWERFUL is Vasille](#how-powerful-is-vasille)
16
- * [Best Practices](#best-practices)
16
+ * [Road Map](#road-map)
17
17
 
18
18
 
19
19
  <hr>
@@ -21,36 +21,42 @@
21
21
  ## Installation
22
22
 
23
23
  ```
24
- npm install vasille --save
25
- npm install vasille-less --save
26
- npm install vasille-magic --save
24
+ npm install vasille-web --save
27
25
  ```
28
26
 
29
27
  ## How to use Vasille
30
28
 
31
- There are several modes to use Vasille.
29
+ Create an app from a template
32
30
 
33
- ### Documentation for beginners (how to create the first project step by step):
34
- * [`Vasille Magic` - perfect for you - `highest-level`](https://gitlab.com/vasille-js/vasille-js/-/blob/v2/doc/magic/GetStarted.md)
35
- * [`Vasille Less Library` - no transcriber usage - `high-level`](https://gitlab.com/vasille-js/vasille-js/-/blob/v2/doc/less/GetStarted.md)
36
- * [`Vasille Core Library` - the hard way - `low-level`](https://gitlab.com/vasille-js/vasille-js/-/blob/v2/doc/core/GetStarted.md)
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
+ ```
37
44
 
38
45
  ### Full documentation:
39
- * [`Vasille Magic API`- compiler writes for you - `highest-level`](https://gitlab.com/vasille-js/vasille-js/-/blob/v2/doc/magic/Vasille-Magic-API.md)
40
- * [`Vasille Less Library API`- write less do more - `high-level`](https://gitlab.com/vasille-js/vasille-js/-/blob/v2/doc/less/Vasille-Less-Library-API.md)
41
- * [`Vasille Core Library API`- write anything - `low-level`](https://gitlab.com/vasille-js/vasille-js/-/blob/v2/doc/core/Vasille-Core-Library-API.md)
46
+ * [Learn `Vasille` in 5 minutes](https://github.com/vasille-js/vasille-js/blob/v3/doc/V3-API.md)
42
47
 
43
- ### Getting ready be example
44
- * [TypeScript Example](https://gitlab.com/vasille-js/learning/vasille-ts-example)
45
- * [JavaScript Example (Vasille Magic not supported)](https://gitlab.com/vasille-js/learning/vasille-js-example)
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)
46
51
 
47
52
  <hr>
48
53
 
49
54
  ## How SAFE is Vasille
50
55
 
51
56
  The safe of your application is ensured by
52
- * `100%` coverage of `vasille` code by unit tests.
57
+ * `100%` coverage of code by unit tests.
53
58
  Each function, each branch is working as designed.
59
+ * OOP, DRY, KISS and SOLID principles are applied.
54
60
  * `strong typing` makes your javascript/typescript code safe as C++ code.
55
61
  All entities of `vasille` core library are strongly typed, including:
56
62
  * data fields & properties.
@@ -58,158 +64,51 @@ All entities of `vasille` core library are strongly typed, including:
58
64
  * methods.
59
65
  * events (defined handlers & event emit).
60
66
  * DOM events & DOM operation (attributing, styling, etc.).
61
- * slots of component.
67
+ * slots of components.
62
68
  * references to children.
63
- * What you write is what you get. There are no hidden operations, you can control everything.
64
69
  * No asynchronous code, when the line of code is executed, the DOM and reactive things are already synced.
65
70
 
66
71
  ## How SIMPLE is Vasille
67
72
 
68
- Can you detect the correct order of console logs in the next code snippet:
69
- ```javascript
70
- import logo from './logo.svg';
71
- import './App.css';
72
- import {useEffect} from 'react';
73
-
74
- function C1 ({children}) {
75
- console.log(1);
76
-
77
- useEffect(() => {
78
- console.log(2);
79
- });
80
-
81
- return <div>{children}</div>;
82
- }
83
-
84
- function C2 () {
85
- console.log(3);
86
-
87
- useEffect(() => {
88
- console.log(4);
89
- });
90
-
91
- return <div></div>;
92
- }
93
-
94
- function App() {
95
- return <C1>
96
- <C2/>
97
- </C1>;
98
- }
73
+ There is the "Hello World":
74
+ ```typescript jsx
75
+ import { compose, mount } from "vasille-dx";
99
76
 
100
- export default App;
101
- ```
77
+ const App = compose(() => {
78
+ <p>Hello world</p>;
79
+ });
102
80
 
103
- So let's see the same example using Vasille:
104
- ```typescript jsx
105
- interface Options extends FragmentOptions {
106
- slot?: () => void;
107
- }
108
-
109
- const C1 : VFragment<Options> = ({slot}) => {
110
- console.log(1);
111
-
112
- <div>
113
- <vxSlot model={slot} />
114
- </div>;
115
-
116
- console.log(2);
117
- }
118
-
119
- const C2: VFragment = () => {
120
- console.log(3);
121
-
122
- <div></div>;
123
-
124
- console.log(4);
125
- }
126
-
127
- const App: VApp = () => {
128
- <C1>
129
- <C2/>
130
- </C1>
131
- }
81
+ mount(document.body, App, {});
132
82
  ```
133
83
 
134
- The `C2` function is sent to `C1` as function,
135
- so it will be called after `console.log(1)` and before `console.log(2)`.
136
- No return is present in this case,
137
- then construction like `for` & `if` can be used in place of `[].map()` and ternary operator.
138
- The component function is called once, no recalls on component update.
139
-
140
84
  ## How POWERFUL is Vasille
141
85
 
142
- The secret of `Vasille` is a good task decomposition. The core library is composed of
143
- an effective reactive module and a DOM generation engine based on it.
144
-
145
- <hr>
146
-
147
- ### Reactivity Module
148
-
149
- Reactivity module is used to create a model of data. It can contain self-updating values,
150
- forward-only shared data. Reactivity of objects/fields can be disabled/enabled manually.
151
-
152
- ![Reactivity Module](https://gitlab.com/vasille-js/vasille-js/-/raw/v2/doc/img/reactive.png)
153
-
154
- * `Destroyable` is an entity which has a custom destructor.
155
- * `IValue<T>` is a common interface for any value container, with next members:
156
- * `get $` gets the encapsulated value.
157
- * `set $` manually update the encapsulated value, if enabled triggers updating of all linked data.
158
- * `disable` disables the reactivity.
159
- * `enable` enables the reactivity and triggers updating of all linked data.
160
- * `Reference<T>` contains a value of type `T`.
161
- * `Mirror<T>` syncs self value with another `IValue` container, can be used to share a value forward-only.
162
- * `Pointer<T>` same as `Mirror`, but it can switch between `IValue` target anytime.
163
- * `Expression<ReturnType, Args...>` is a self-updating value.
164
- * `Reactive` is a reactive object which can have multiple reactive fields, emit/receive events/signals.
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).
165
96
 
166
97
  <hr>
167
98
 
168
- ### DOM Generation Engine
169
-
170
- DOM Generation Engine is used to describe a virtual DOM of reactive fragments,
171
- which will be reflected into a browser DOM and keep up to date it.
172
-
173
- ![DOM Generation Engine](https://gitlab.com/vasille-js/vasille-js/-/raw/v2/doc/img/nodes.png)
174
-
175
- * `Fragment` describes a virtual DOM node, which has siblings, children, parent & slots.
176
- * `TextNode` reflects a `Text` node.
177
- * `INode` reflects a `Element` node.
178
- * `Tag` reflect a self created `Element` node.
179
- * `Extension` reflects an existing `Element` node.
180
- * `Component` reflects a `Element` node created by a `Tag` child.
181
- * `AppNode` is root of a `Vasille` application, can be used to create applications in application.
182
- * `App` is root of a definitive `Vasille` application.
183
- * `DebugNode` reflects a `Comment` node, useful for debug.
184
- * `Watch` recompose children nodes on model value change.
185
- * `RepeatNode` creates multiples children nodes using the same code multiple time.
186
- * `BaseView` represent a view in context of MVC (Model-View-Controller).
187
- * `ObjectView` repeats slot content for each value of `ObjectModel`.
188
- * `MapView` repeats slot content for each `MapModel` value.
189
- * `SetView` repeats slot content for each `SetModel` value.
190
- * `ArrayView` repeats slot content for each `ArrayModel` value respecting its order.
99
+ ## Road map
191
100
 
192
- <hr>
193
-
194
- ### CDN
195
-
196
- ```html
197
- <script src="https://unpkg.com/vasille"></script>
198
- ```
199
-
200
- ## Best Practices applicable to Vasille Core Library
201
-
202
- * [Reactive Object Practice](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/reactive-object.ts)
203
- * [Application](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/application.ts)
204
- * [Application in Application (Micro frontends)](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/application-in-application.ts)
205
- * [Signaling](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/signaling.ts)
206
- * [Forward Only Data Exchange](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/forward-only.ts)
207
- * [Absolute, Relative & Auto Values](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/auto-value.ts)
208
- * [Signaling Intercepting](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/singaling-intercepting.ts)
209
- * [Debugging](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/debugging.ts)
210
- * [Fragment vs Component](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/fragment-component.ts)
211
- * [Extensions](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/extension.ts)
212
- * [Model-View-Controller](https://gitlab.com/vasille-js/vasille-practices/-/blob/main/practices/model-view-controller.ts)
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.
213
112
 
214
113
  ## Questions
215
114
 
@@ -218,3 +117,6 @@ If you have questions, feel free to contact the maintainer of the project:
218
117
  * [Author's Email](mailto:vas.lixcode@gmail.com)
219
118
  * [Author's Telegram](https://t.me/lixcode)
220
119
 
120
+ <hr>
121
+
122
+ **Made in Moldova** 🇲🇩
@@ -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 === 'boolean') {
19
- node.node.setAttribute(name, "");
18
+ if (typeof value === "boolean") {
19
+ node.element.setAttribute(name, "");
20
20
  }
21
21
  else {
22
- node.node.setAttribute(name, `${value}`);
22
+ node.element.setAttribute(name, `${value}`);
23
23
  }
24
24
  }
25
25
  else {
26
- node.node.removeAttribute(name);
26
+ node.element.removeAttribute(name);
27
27
  }
28
28
  });
29
- this.$seal();
30
29
  }
31
30
  }
@@ -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.$on(this.func);
18
+ this.binding.on(this.func);
20
19
  this.func(this.binding.$);
21
20
  }
22
21
  /**
23
22
  * Just clear bindings
24
23
  */
25
- $destroy() {
26
- this.binding.$off(this.func);
27
- super.$destroy();
24
+ destroy() {
25
+ this.binding.off(this.func);
26
+ super.destroy();
28
27
  }
29
28
  }
@@ -1,9 +1,9 @@
1
1
  import { Binding } from "./binding";
2
2
  function addClass(node, cl) {
3
- node.node.classList.add(cl);
3
+ node.element.classList.add(cl);
4
4
  }
5
5
  function removeClass(node, cl) {
6
- node.node.classList.remove(cl);
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
  }
@@ -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((value) => {
17
- if (node.node instanceof HTMLElement) {
18
- node.node.style.setProperty(name, value);
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
  }
@@ -0,0 +1,3 @@
1
+ export const config = {
2
+ debugUi: true,
3
+ };
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
- * Private stuff of a reactive object
18
- * @class ReactivePrivate
6
+ * A reactive object
7
+ * @class Reactive
19
8
  * @extends Destroyable
20
9
  */
21
- export class ReactivePrivate extends Destroyable {
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.watch = new Set;
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
- $.watch.add(ref);
31
+ this._watch.add(ref);
88
32
  return ref;
89
33
  }
90
34
  /**
91
- * Create a mirror
92
- * @param value {IValue} value to mirror
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 Mirror(value, true);
105
- this.$.watch.add(mirror);
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
- point(value, forwardOnly = false) {
114
- const $ = this.$;
115
- const pointer = new Pointer(value, forwardOnly);
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(model) {
124
- this.$.models.add(model);
125
- return model;
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
- const $ = this.$;
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, !this.$.frozen, ...values);
144
- const $ = this.$;
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.$.onDestroy = func;
229
- }
230
- $destroy() {
231
- super.$destroy();
232
- this.$.$destroy();
233
- this.$ = null;
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
  }