vasille 1.2.9 → 2.0.3

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 (133) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +195 -129
  3. package/cdn/es2015.js +3231 -0
  4. package/cdn/es5.js +3675 -0
  5. package/flow-typed/vasille.js +839 -0
  6. package/lib/binding/attribute.js +32 -0
  7. package/lib/binding/binding.js +39 -0
  8. package/lib/binding/class.js +51 -0
  9. package/lib/binding/style.js +29 -0
  10. package/lib/core/core.js +186 -0
  11. package/lib/core/destroyable.js +45 -0
  12. package/lib/core/errors.js +16 -0
  13. package/lib/core/executor.js +154 -0
  14. package/lib/core/ivalue.js +56 -0
  15. package/lib/core/signal.js +50 -0
  16. package/lib/core/slot.js +47 -0
  17. package/lib/index.js +27 -22
  18. package/lib/models/array-model.js +208 -0
  19. package/lib/models/listener.js +130 -0
  20. package/lib/models/map-model.js +66 -0
  21. package/lib/models/model.js +1 -0
  22. package/lib/models/object-model.js +78 -0
  23. package/lib/models/set-model.js +62 -0
  24. package/lib/node/app.js +39 -0
  25. package/lib/node/interceptor.js +83 -0
  26. package/lib/node/node.js +1204 -0
  27. package/lib/node/watch.js +27 -0
  28. package/lib/value/expression.js +83 -0
  29. package/lib/value/mirror.js +58 -0
  30. package/lib/value/pointer.js +26 -0
  31. package/lib/value/reference.js +55 -0
  32. package/lib/views/array-view.js +21 -0
  33. package/lib/views/base-view.js +49 -0
  34. package/lib/views/map-view.js +19 -0
  35. package/lib/views/object-view.js +19 -0
  36. package/lib/views/repeat-node.js +106 -0
  37. package/lib/views/repeater.js +63 -0
  38. package/lib/views/set-view.js +22 -0
  39. package/package.json +26 -18
  40. package/types/binding/attribute.d.ts +23 -0
  41. package/types/binding/binding.d.ts +30 -0
  42. package/types/binding/class.d.ts +23 -0
  43. package/types/binding/style.d.ts +23 -0
  44. package/types/core/core.d.ts +144 -0
  45. package/types/core/destroyable.d.ts +15 -0
  46. package/types/core/errors.d.ts +4 -0
  47. package/types/core/executor.d.ts +87 -0
  48. package/types/core/ivalue.d.ts +45 -0
  49. package/types/core/signal.d.ts +35 -0
  50. package/types/core/slot.d.ts +45 -0
  51. package/types/index.d.ts +27 -21
  52. package/types/models/array-model.d.ts +103 -0
  53. package/types/models/listener.d.ts +74 -0
  54. package/types/models/map-model.d.ts +35 -0
  55. package/types/models/model.d.ts +19 -0
  56. package/types/models/object-model.d.ts +36 -0
  57. package/types/models/set-model.d.ts +34 -0
  58. package/types/node/app.d.ts +42 -0
  59. package/types/node/interceptor.d.ts +50 -0
  60. package/types/node/node.d.ts +741 -0
  61. package/types/node/watch.d.ts +23 -0
  62. package/types/value/expression.d.ts +60 -0
  63. package/types/value/mirror.d.ts +35 -0
  64. package/types/value/pointer.d.ts +19 -0
  65. package/types/value/reference.d.ts +30 -0
  66. package/types/views/array-view.d.ts +13 -0
  67. package/types/views/base-view.d.ts +43 -0
  68. package/types/views/map-view.d.ts +11 -0
  69. package/types/views/object-view.d.ts +11 -0
  70. package/types/views/repeat-node.d.ts +35 -0
  71. package/types/views/repeater.d.ts +38 -0
  72. package/types/views/set-view.d.ts +11 -0
  73. package/CHANGELOG.md +0 -23
  74. package/img/favicon.svg +0 -441
  75. package/img/getLocus.svg +0 -18
  76. package/img/logo.png +0 -0
  77. package/img/logo.svg +0 -550
  78. package/img/scores-o-log.png +0 -0
  79. package/img/scores-o.png +0 -0
  80. package/img/scores-wo-log.png +0 -0
  81. package/img/scores-wo.png +0 -0
  82. package/img/x1-x32.png +0 -0
  83. package/lib/attribute.js +0 -71
  84. package/lib/attribute.js.map +0 -1
  85. package/lib/bind.js +0 -286
  86. package/lib/bind.js.map +0 -1
  87. package/lib/class.js +0 -97
  88. package/lib/class.js.map +0 -1
  89. package/lib/executor.js +0 -167
  90. package/lib/executor.js.map +0 -1
  91. package/lib/index.js.map +0 -1
  92. package/lib/interfaces/core.js +0 -247
  93. package/lib/interfaces/core.js.map +0 -1
  94. package/lib/interfaces/destroyable.js +0 -39
  95. package/lib/interfaces/destroyable.js.map +0 -1
  96. package/lib/interfaces/errors.js +0 -49
  97. package/lib/interfaces/errors.js.map +0 -1
  98. package/lib/interfaces/ibind.js +0 -31
  99. package/lib/interfaces/ibind.js.map +0 -1
  100. package/lib/interfaces/idefinition.js +0 -64
  101. package/lib/interfaces/idefinition.js.map +0 -1
  102. package/lib/interfaces/ivalue.js +0 -60
  103. package/lib/interfaces/ivalue.js.map +0 -1
  104. package/lib/models.js +0 -579
  105. package/lib/models.js.map +0 -1
  106. package/lib/node.js +0 -2155
  107. package/lib/node.js.map +0 -1
  108. package/lib/property.js +0 -38
  109. package/lib/property.js.map +0 -1
  110. package/lib/style.js +0 -66
  111. package/lib/style.js.map +0 -1
  112. package/lib/value.js +0 -203
  113. package/lib/value.js.map +0 -1
  114. package/lib/views.js +0 -688
  115. package/lib/views.js.map +0 -1
  116. package/types/attribute.d.ts +0 -18
  117. package/types/bind.d.ts +0 -72
  118. package/types/class.d.ts +0 -19
  119. package/types/data.d.ts +0 -11
  120. package/types/event.d.ts +0 -10
  121. package/types/executor.d.ts +0 -57
  122. package/types/interfaces/core.d.ts +0 -129
  123. package/types/interfaces/destroyable.d.ts +0 -11
  124. package/types/interfaces/errors.d.ts +0 -24
  125. package/types/interfaces/ibind.d.ts +0 -19
  126. package/types/interfaces/idefinition.d.ts +0 -29
  127. package/types/interfaces/ivalue.d.ts +0 -40
  128. package/types/models.d.ts +0 -179
  129. package/types/node.d.ts +0 -906
  130. package/types/property.d.ts +0 -9
  131. package/types/style.d.ts +0 -28
  132. package/types/value.d.ts +0 -43
  133. package/types/views.d.ts +0 -135
@@ -0,0 +1,47 @@
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
+ }
package/lib/index.js CHANGED
@@ -1,22 +1,27 @@
1
- import { Expression } from "./bind.js";
2
- import { Destroyable } from "./interfaces/destroyable.js";
3
- import { IBind } from "./interfaces/ibind.js";
4
- import { IValue } from "./interfaces/ivalue.js";
5
- import { ArrayModel, MapModel, ObjectModel, SetModel } from "./models.js";
6
- import { App, INode, Extension, Tag, TextNode, Component } from "./node.js";
7
- import { Pointer, Reference } from "./value.js";
8
- import { ArrayView, MapView, ObjectView, SetView } from "./views.js";
9
-
10
-
11
-
12
- export {
13
- Expression,
14
- Destroyable,
15
- IBind, IValue,
16
- ArrayModel, MapModel, ObjectModel, SetModel,
17
- App, INode, Tag, Extension, TextNode, Component,
18
- Pointer, Reference,
19
- ArrayView, MapView, ObjectView, SetView
20
- };
21
-
22
- //# sourceMappingURL=index.js.map
1
+ import { Destroyable } from "./core/destroyable";
2
+ import { Executor, InstantExecutor, TimeoutExecutor } from "./core/executor";
3
+ import { Reactive } from "./core/core";
4
+ import { IValue } from "./core/ivalue";
5
+ import { Signal } from "./core/signal";
6
+ import { Slot } from "./core/slot";
7
+ import { ArrayModel } from "./models/array-model";
8
+ import { Listener } from "./models/listener";
9
+ import { MapModel } from "./models/map-model";
10
+ import { ObjectModel } from "./models/object-model";
11
+ import { SetModel } from "./models/set-model";
12
+ import { App, AppNode } from "./node/app";
13
+ import { Interceptor, InterceptorNode } from "./node/interceptor";
14
+ import { Component, Extension, Fragment, INode, Tag } from "./node/node";
15
+ import { Expression } from "./value/expression";
16
+ import { Mirror } from "./value/mirror";
17
+ import { Pointer } from "./value/pointer";
18
+ import { Reference } from "./value/reference";
19
+ import { ArrayView } from "./views/array-view";
20
+ import { BaseView } from "./views/base-view";
21
+ import { MapView } from "./views/map-view";
22
+ import { ObjectView } from "./views/object-view";
23
+ import { RepeatNode } from "./views/repeat-node";
24
+ import { Repeater } from "./views/repeater";
25
+ import { SetView } from "./views/set-view";
26
+ import { Binding } from "./binding/binding";
27
+ export { Destroyable, IValue, Reference, Mirror, Pointer, ArrayModel, MapModel, ObjectModel, SetModel, RepeatNode, Repeater, BaseView, Listener, ArrayView, MapView, ObjectView, SetView, Fragment, INode, Tag, Component, Extension, AppNode, App, Executor, InstantExecutor, TimeoutExecutor, Signal, Slot, Interceptor, InterceptorNode, Expression, Binding, Reactive, };
@@ -0,0 +1,208 @@
1
+ import { Listener } from "./listener";
2
+ /**
3
+ * Model based on Array class
4
+ * @extends Array
5
+ * @implements IModel
6
+ */
7
+ export class ArrayModel extends Array {
8
+ /**
9
+ * @param data {Array} input data
10
+ */
11
+ constructor(data = []) {
12
+ super();
13
+ Object.defineProperty(this, 'listener', {
14
+ value: new Listener,
15
+ writable: false,
16
+ configurable: false
17
+ });
18
+ for (let i = 0; i < data.length; i++) {
19
+ super.push(data[i]);
20
+ }
21
+ }
22
+ /* Array members */
23
+ /**
24
+ * Gets the last item of array
25
+ * @return {*} the last item of array
26
+ */
27
+ get last() {
28
+ return this.length ? this[this.length - 1] : null;
29
+ }
30
+ /**
31
+ * Calls Array.fill and notify about changes
32
+ * @param value {*} value to fill with
33
+ * @param start {?number} begin index
34
+ * @param end {?number} end index
35
+ */
36
+ fill(value, start, end) {
37
+ if (!start) {
38
+ start = 0;
39
+ }
40
+ if (!end) {
41
+ end = this.length;
42
+ }
43
+ for (let i = start; i < end; i++) {
44
+ this.listener.emitRemoved(this[i], this[i]);
45
+ this[i] = value;
46
+ this.listener.emitAdded(value, value);
47
+ }
48
+ return this;
49
+ }
50
+ /**
51
+ * Calls Array.pop and notify about changes
52
+ * @return {*} removed value
53
+ */
54
+ pop() {
55
+ const v = super.pop();
56
+ if (v !== undefined) {
57
+ this.listener.emitRemoved(v, v);
58
+ }
59
+ return v;
60
+ }
61
+ /**
62
+ * Calls Array.push and notify about changes
63
+ * @param items {...*} values to push
64
+ * @return {number} new length of array
65
+ */
66
+ push(...items) {
67
+ items.forEach(item => {
68
+ this.listener.emitAdded(item, item);
69
+ super.push(item);
70
+ });
71
+ return this.length;
72
+ }
73
+ /**
74
+ * Calls Array.shift and notify about changed
75
+ * @return {*} the shifted value
76
+ */
77
+ shift() {
78
+ const v = super.shift();
79
+ if (v !== undefined) {
80
+ this.listener.emitRemoved(v, v);
81
+ }
82
+ return v;
83
+ }
84
+ /**
85
+ * Calls Array.splice and notify about changed
86
+ * @param start {number} start index
87
+ * @param deleteCount {?number} delete count
88
+ * @param items {...*}
89
+ * @return {ArrayModel} a pointer to this
90
+ */
91
+ splice(start, deleteCount, ...items) {
92
+ start = Math.min(start, this.length);
93
+ deleteCount = deleteCount || this.length - start;
94
+ const before = this[start + deleteCount];
95
+ for (let i = 0; i < deleteCount; i++) {
96
+ const index = start + deleteCount - i - 1;
97
+ if (this[index] !== undefined) {
98
+ this.listener.emitRemoved(this[index], this[index]);
99
+ }
100
+ }
101
+ for (let i = 0; i < items.length; i++) {
102
+ this.listener.emitAdded(before, items[i]);
103
+ }
104
+ return new ArrayModel(super.splice(start, deleteCount, ...items));
105
+ }
106
+ /**
107
+ * Calls Array.unshift and notify about changed
108
+ * @param items {...*} values to insert
109
+ * @return {number} the length after prepend
110
+ */
111
+ unshift(...items) {
112
+ for (let i = 0; i < items.length; i++) {
113
+ this.listener.emitAdded(this[i], items[i]);
114
+ }
115
+ return super.unshift(...items);
116
+ }
117
+ /**
118
+ * Inserts a value to the end of array
119
+ * @param v {*} value to insert
120
+ */
121
+ append(v) {
122
+ this.listener.emitAdded(null, v);
123
+ super.push(v);
124
+ return this;
125
+ }
126
+ /**
127
+ * Clears array
128
+ * @return {this} a pointer to this
129
+ */
130
+ clear() {
131
+ this.forEach(v => {
132
+ this.listener.emitRemoved(v, v);
133
+ });
134
+ super.splice(0);
135
+ return this;
136
+ }
137
+ /**
138
+ * Inserts a value to position `index`
139
+ * @param index {number} index to insert value
140
+ * @param v {*} value to insert
141
+ * @return {this} a pointer to this
142
+ */
143
+ insert(index, v) {
144
+ this.listener.emitAdded(this[index], v);
145
+ super.splice(index, 0, v);
146
+ return this;
147
+ }
148
+ /**
149
+ * Inserts a value to the beginning of array
150
+ * @param v {*} value to insert
151
+ * @return {this} a pointer to this
152
+ */
153
+ prepend(v) {
154
+ this.listener.emitAdded(this[0], v);
155
+ super.unshift(v);
156
+ return this;
157
+ }
158
+ /**
159
+ * Removes a value from an index
160
+ * @param index {number} index of value to remove
161
+ * @return {this} a pointer to this
162
+ */
163
+ removeAt(index) {
164
+ if (index > 0 && index < this.length) {
165
+ this.listener.emitRemoved(this[index], this[index]);
166
+ super.splice(index, 1);
167
+ }
168
+ return this;
169
+ }
170
+ /**
171
+ * Removes the first value of array
172
+ * @return {this} a pointer to this
173
+ */
174
+ removeFirst() {
175
+ if (this.length) {
176
+ this.listener.emitRemoved(this[0], this[0]);
177
+ super.shift();
178
+ }
179
+ return this;
180
+ }
181
+ /**
182
+ * Removes the ast value of array
183
+ * @return {this} a pointer to this
184
+ */
185
+ removeLast() {
186
+ const last = this.last;
187
+ if (last != null) {
188
+ this.listener.emitRemoved(this[this.length - 1], last);
189
+ super.pop();
190
+ }
191
+ return this;
192
+ }
193
+ /**
194
+ * Remove the first occurrence of value
195
+ * @param v {*} value to remove
196
+ * @return {this}
197
+ */
198
+ removeOne(v) {
199
+ this.removeAt(this.indexOf(v));
200
+ return this;
201
+ }
202
+ enableReactivity() {
203
+ this.listener.enableReactivity();
204
+ }
205
+ disableReactivity() {
206
+ this.listener.disableReactivity();
207
+ }
208
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Represent a listener for a model
3
+ * @class Listener
4
+ */
5
+ export class Listener {
6
+ constructor() {
7
+ Object.defineProperties(this, {
8
+ onAdded: {
9
+ value: new Set,
10
+ writable: false,
11
+ configurable: false
12
+ },
13
+ onRemoved: {
14
+ value: new Set,
15
+ writable: false,
16
+ configurable: false
17
+ },
18
+ frozen: {
19
+ value: false,
20
+ writable: true,
21
+ configurable: false
22
+ },
23
+ queue: {
24
+ value: [],
25
+ writable: false,
26
+ configurable: false
27
+ }
28
+ });
29
+ }
30
+ /**
31
+ * Exclude the repeated operation in queue
32
+ * @private
33
+ */
34
+ excludeRepeat(index) {
35
+ this.queue.forEach((item, i) => {
36
+ if (item.index === index) {
37
+ this.queue.splice(i, 1);
38
+ return true;
39
+ }
40
+ });
41
+ return false;
42
+ }
43
+ /**
44
+ * Emits added event to listeners
45
+ * @param index {*} index of value
46
+ * @param value {*} value of added item
47
+ */
48
+ emitAdded(index, value) {
49
+ if (this.frozen) {
50
+ if (!this.excludeRepeat(index)) {
51
+ this.queue.push({ sign: true, index, value });
52
+ }
53
+ }
54
+ else {
55
+ this.onAdded.forEach(handler => {
56
+ handler(index, value);
57
+ });
58
+ }
59
+ }
60
+ /**
61
+ * Emits removed event to listeners
62
+ * @param index {*} index of removed value
63
+ * @param value {*} value of removed item
64
+ */
65
+ emitRemoved(index, value) {
66
+ if (this.frozen) {
67
+ if (!this.excludeRepeat(index)) {
68
+ this.queue.push({ sign: false, index, value });
69
+ }
70
+ }
71
+ else {
72
+ this.onRemoved.forEach(handler => {
73
+ handler(index, value);
74
+ });
75
+ }
76
+ }
77
+ /**
78
+ * Adds a handler to added event
79
+ * @param handler {function} function to run on event emitting
80
+ */
81
+ onAdd(handler) {
82
+ this.onAdded.add(handler);
83
+ }
84
+ /**
85
+ * Adds a handler to removed event
86
+ * @param handler {function} function to run on event emitting
87
+ */
88
+ onRemove(handler) {
89
+ this.onRemoved.add(handler);
90
+ }
91
+ /**
92
+ * Removes an handler from added event
93
+ * @param handler {function} handler to remove
94
+ */
95
+ offAdd(handler) {
96
+ this.onAdded.delete(handler);
97
+ }
98
+ /**
99
+ * Removes an handler form removed event
100
+ * @param handler {function} handler to remove
101
+ */
102
+ offRemove(handler) {
103
+ this.onRemoved.delete(handler);
104
+ }
105
+ /**
106
+ * Run all queued operation and enable reactivity
107
+ */
108
+ enableReactivity() {
109
+ this.queue.forEach(item => {
110
+ if (item.sign) {
111
+ this.onAdded.forEach(handler => {
112
+ handler(item.index, item.value);
113
+ });
114
+ }
115
+ else {
116
+ this.onRemoved.forEach(handler => {
117
+ handler(item.index, item.value);
118
+ });
119
+ }
120
+ });
121
+ this.queue.splice(0);
122
+ this.frozen = false;
123
+ }
124
+ /**
125
+ * Disable the reactivity and enable the queue
126
+ */
127
+ disableReactivity() {
128
+ this.frozen = true;
129
+ }
130
+ }
@@ -0,0 +1,66 @@
1
+ import { Listener } from "./listener";
2
+ /**
3
+ * A Map based memory
4
+ * @class MapModel
5
+ * @extends Map
6
+ * @implements IModel
7
+ */
8
+ export class MapModel extends Map {
9
+ /**
10
+ * Constructs a map model
11
+ * @param map {[*, *][]} input data
12
+ */
13
+ constructor(map = []) {
14
+ super();
15
+ Object.defineProperty(this, 'listener', {
16
+ value: new Listener,
17
+ writable: false,
18
+ configurable: false
19
+ });
20
+ map.forEach(([key, value]) => {
21
+ super.set(key, value);
22
+ });
23
+ }
24
+ /**
25
+ * Calls Map.clear and notify abut changes
26
+ */
27
+ clear() {
28
+ this.forEach((value, key) => {
29
+ this.listener.emitRemoved(key, value);
30
+ });
31
+ super.clear();
32
+ }
33
+ /**
34
+ * Calls Map.delete and notify abut changes
35
+ * @param key {*} key
36
+ * @return {boolean} true if removed something, otherwise false
37
+ */
38
+ delete(key) {
39
+ const tmp = super.get(key);
40
+ if (tmp) {
41
+ this.listener.emitRemoved(key, tmp);
42
+ }
43
+ return super.delete(key);
44
+ }
45
+ /**
46
+ * Calls Map.set and notify abut changes
47
+ * @param key {*} key
48
+ * @param value {*} value
49
+ * @return {MapModel} a pointer to this
50
+ */
51
+ set(key, value) {
52
+ const tmp = super.get(key);
53
+ if (tmp) {
54
+ this.listener.emitRemoved(key, tmp);
55
+ }
56
+ super.set(key, value);
57
+ this.listener.emitAdded(key, value);
58
+ return this;
59
+ }
60
+ enableReactivity() {
61
+ this.listener.enableReactivity();
62
+ }
63
+ disableReactivity() {
64
+ this.listener.disableReactivity();
65
+ }
66
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,78 @@
1
+ import { Listener } from "./listener";
2
+ /**
3
+ * Object based model
4
+ * @extends Object
5
+ */
6
+ export class ObjectModel extends Object {
7
+ /**
8
+ * Constructs a object model
9
+ * @param obj {Object} input data
10
+ */
11
+ constructor(obj = {}) {
12
+ super();
13
+ Object.defineProperty(this, 'listener', {
14
+ value: new Listener,
15
+ writable: false,
16
+ configurable: false
17
+ });
18
+ for (const i in obj) {
19
+ Object.defineProperty(this, i, {
20
+ value: obj[i],
21
+ configurable: true,
22
+ writable: true,
23
+ enumerable: true
24
+ });
25
+ this.listener.emitAdded(i, obj[i]);
26
+ }
27
+ }
28
+ /**
29
+ * Gets a value of a field
30
+ * @param key {string}
31
+ * @return {*}
32
+ */
33
+ get(key) {
34
+ const ts = this;
35
+ return ts[key];
36
+ }
37
+ /**
38
+ * Sets an object property value
39
+ * @param key {string} property name
40
+ * @param v {*} property value
41
+ * @return {ObjectModel} a pointer to this
42
+ */
43
+ set(key, v) {
44
+ const ts = this;
45
+ // eslint-disable-next-line no-prototype-builtins
46
+ if (ts.hasOwnProperty(key)) {
47
+ this.listener.emitRemoved(key, ts[key]);
48
+ ts[key] = v;
49
+ }
50
+ else {
51
+ Object.defineProperty(ts, key, {
52
+ value: v,
53
+ configurable: true,
54
+ writable: true,
55
+ enumerable: true
56
+ });
57
+ }
58
+ this.listener.emitAdded(key, ts[key]);
59
+ return this;
60
+ }
61
+ /**
62
+ * Deletes an object property
63
+ * @param key {string} property name
64
+ */
65
+ delete(key) {
66
+ const ts = this;
67
+ if (ts[key]) {
68
+ this.listener.emitRemoved(key, ts[key]);
69
+ delete ts[key];
70
+ }
71
+ }
72
+ enableReactivity() {
73
+ this.listener.enableReactivity();
74
+ }
75
+ disableReactivity() {
76
+ this.listener.disableReactivity();
77
+ }
78
+ }
@@ -0,0 +1,62 @@
1
+ import { Listener } from "./listener";
2
+ /**
3
+ * A Set based model
4
+ * @class SetModel
5
+ * @extends Set
6
+ * @implements IModel
7
+ */
8
+ export class SetModel extends Set {
9
+ /**
10
+ * Constructs a set model based on a set
11
+ * @param set {Set} input data
12
+ */
13
+ constructor(set = []) {
14
+ super();
15
+ Object.defineProperty(this, 'listener', {
16
+ value: new Listener,
17
+ writable: false,
18
+ configurable: false
19
+ });
20
+ set.forEach(item => {
21
+ super.add(item);
22
+ });
23
+ }
24
+ /**
25
+ * Calls Set.add and notify abut changes
26
+ * @param value {*} value
27
+ * @return {this} a pointer to this
28
+ */
29
+ add(value) {
30
+ if (!super.has(value)) {
31
+ this.listener.emitAdded(value, value);
32
+ super.add(value);
33
+ }
34
+ return this;
35
+ }
36
+ /**
37
+ * Calls Set.clear and notify abut changes
38
+ */
39
+ clear() {
40
+ this.forEach(item => {
41
+ this.listener.emitRemoved(item, item);
42
+ });
43
+ super.clear();
44
+ }
45
+ /**
46
+ * Calls Set.delete and notify abut changes
47
+ * @param value {*}
48
+ * @return {boolean} true if a value was deleted, otherwise false
49
+ */
50
+ delete(value) {
51
+ if (super.has(value)) {
52
+ this.listener.emitRemoved(value, value);
53
+ }
54
+ return super.delete(value);
55
+ }
56
+ enableReactivity() {
57
+ this.listener.enableReactivity();
58
+ }
59
+ disableReactivity() {
60
+ this.listener.disableReactivity();
61
+ }
62
+ }
@@ -0,0 +1,39 @@
1
+ import { instantExecutor, timeoutExecutor } from "../core/executor";
2
+ import { INode } from "./node";
3
+ /**
4
+ * Application Node
5
+ * @class AppNode
6
+ * @extends INode
7
+ */
8
+ export class AppNode extends INode {
9
+ /**
10
+ * @param options {Object} Application options
11
+ */
12
+ constructor(options) {
13
+ super();
14
+ this.$run = (options === null || options === void 0 ? void 0 : options.executor) || ((options === null || options === void 0 ? void 0 : options.freezeUi) === false ? timeoutExecutor : instantExecutor);
15
+ this.$debugUi = (options === null || options === void 0 ? void 0 : options.debugUi) || false;
16
+ }
17
+ }
18
+ /**
19
+ * Represents a Vasille.js application
20
+ * @class App
21
+ * @extends AppNode
22
+ */
23
+ export class App extends AppNode {
24
+ /**
25
+ * Constructs an app node
26
+ * @param node {Element} The root of application
27
+ * @param options {Object} Application options
28
+ */
29
+ constructor(node, options) {
30
+ super(options);
31
+ this.$.node = node;
32
+ this.$preinit(this, this);
33
+ this.$seal();
34
+ }
35
+ $$appendNode(node) {
36
+ const $ = this.$;
37
+ $.app.$run.appendChild($.node, node);
38
+ }
39
+ }