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,32 @@
1
+ import { Binding } from "./binding";
2
+ /**
3
+ * Represents an Attribute binding description
4
+ * @class AttributeBinding
5
+ * @extends Binding
6
+ */
7
+ export class AttributeBinding extends Binding {
8
+ /**
9
+ * Constructs an attribute binding description
10
+ * @param node {INode} the vasille node
11
+ * @param name {String} the name of attribute
12
+ * @param value {IValue} value to bind
13
+ */
14
+ constructor(node, name, value) {
15
+ super(node, name, value);
16
+ }
17
+ /**
18
+ * Generates a function which updates the attribute value
19
+ * @param name {String} The name of attribute
20
+ * @returns {Function} a function which will update attribute value
21
+ */
22
+ bound(name) {
23
+ return function (node, value) {
24
+ if (value) {
25
+ node.app.$run.setAttribute(node.node, name, value);
26
+ }
27
+ else {
28
+ node.app.$run.removeAttribute(node.node, name);
29
+ }
30
+ };
31
+ }
32
+ }
@@ -0,0 +1,39 @@
1
+ import { Destroyable } from "../core/destroyable";
2
+ import { notOverwritten } from "../core/errors";
3
+ /**
4
+ * Describe a common binding logic
5
+ * @class Binding
6
+ * @extends Destroyable
7
+ */
8
+ export class Binding extends Destroyable {
9
+ /**
10
+ * Constructs a common binding logic
11
+ * @param node {INode} the vasille node
12
+ * @param name {String} the name of property/attribute/class
13
+ * @param value {IValue} the value to bind
14
+ */
15
+ constructor(node, name, value) {
16
+ super();
17
+ this.updateFunc = this.bound(name).bind(null, node);
18
+ this.binding = value;
19
+ this.binding.on(this.updateFunc);
20
+ this.updateFunc(this.binding.$);
21
+ this.$seal();
22
+ }
23
+ /**
24
+ * Is a virtual function to get the specific bind function
25
+ * @param name {String} the name of attribute/property
26
+ * @returns {Function} a function to update attribute/property value
27
+ * @throws Always throws and must be overloaded in child class
28
+ */
29
+ bound(name) {
30
+ throw notOverwritten();
31
+ }
32
+ /**
33
+ * Just clear bindings
34
+ */
35
+ $destroy() {
36
+ this.binding.off(this.updateFunc);
37
+ super.$destroy();
38
+ }
39
+ }
@@ -0,0 +1,51 @@
1
+ import { Binding } from "./binding";
2
+ /**
3
+ * Represents a HTML class binding description
4
+ * @class ClassBinding
5
+ * @extends Binding
6
+ */
7
+ export class ClassBinding extends Binding {
8
+ /**
9
+ * Constructs an HTML class binding description
10
+ * @param node {INode} the vasille node
11
+ * @param name {String} the name of class
12
+ * @param value {IValue} the value to bind
13
+ */
14
+ constructor(node, name, value) {
15
+ super(node, name, value);
16
+ this.$seal();
17
+ }
18
+ /**
19
+ * Generates a function which updates the html class value
20
+ * @param name {String} The name of attribute
21
+ * @returns {Function} a function which will update attribute value
22
+ */
23
+ bound(name) {
24
+ let current = null;
25
+ function addClass(node, cl) {
26
+ node.app.$run.addClass(node.node, cl);
27
+ }
28
+ function removeClass(node, cl) {
29
+ node.app.$run.removeClass(node.node, cl);
30
+ }
31
+ return (node, value) => {
32
+ if (value !== current) {
33
+ if (typeof current === "string" && current !== "") {
34
+ removeClass(node, current);
35
+ }
36
+ if (typeof value === "boolean") {
37
+ if (value) {
38
+ addClass(node, name);
39
+ }
40
+ else {
41
+ removeClass(node, name);
42
+ }
43
+ }
44
+ else if (typeof value === "string" && value !== "") {
45
+ addClass(node, value);
46
+ }
47
+ current = value;
48
+ }
49
+ };
50
+ }
51
+ }
@@ -0,0 +1,29 @@
1
+ import { Binding } from "./binding";
2
+ /**
3
+ * Describes a style attribute binding
4
+ * @class StyleBinding
5
+ * @extends Binding
6
+ */
7
+ export class StyleBinding extends Binding {
8
+ /**
9
+ * Constructs a style binding attribute
10
+ * @param node {INode} the vasille node
11
+ * @param name {string} the name of style property
12
+ * @param value {IValue} the value to bind
13
+ */
14
+ constructor(node, name, value) {
15
+ super(node, name, value);
16
+ }
17
+ /**
18
+ * Generates a function to update style property value
19
+ * @param name {string}
20
+ * @returns {Function} a function to update style property
21
+ */
22
+ bound(name) {
23
+ return function (node, value) {
24
+ if (node.node instanceof HTMLElement) {
25
+ node.app.$run.setStyle(node.node, name, value);
26
+ }
27
+ };
28
+ }
29
+ }
@@ -0,0 +1,186 @@
1
+ import { Destroyable } from "./destroyable.js";
2
+ import { wrongBinding } from "./errors";
3
+ import { IValue } from "./ivalue.js";
4
+ import { Expression } from "../value/expression";
5
+ import { Reference } from "../value/reference";
6
+ import { Pointer } from "../value/pointer";
7
+ import { Mirror } from "../value/mirror";
8
+ /**
9
+ * Private stuff of a reactive object
10
+ * @class ReactivePrivate
11
+ * @extends Destroyable
12
+ */
13
+ export class ReactivePrivate extends Destroyable {
14
+ constructor() {
15
+ super();
16
+ /**
17
+ * A list of user-defined values
18
+ * @type {Set}
19
+ */
20
+ this.watch = new Set;
21
+ /**
22
+ * A list of user-defined bindings
23
+ * @type {Set}
24
+ */
25
+ this.bindings = new Set;
26
+ /**
27
+ * A list of user defined models
28
+ */
29
+ this.models = new Set;
30
+ /**
31
+ * Reactivity switch state
32
+ * @type {boolean}
33
+ */
34
+ this.enabled = true;
35
+ /**
36
+ * The frozen state of object
37
+ * @type {boolean}
38
+ */
39
+ this.frozen = false;
40
+ this.$seal();
41
+ }
42
+ $destroy() {
43
+ var _a;
44
+ this.watch.forEach(value => value.$destroy());
45
+ this.watch.clear();
46
+ this.bindings.forEach(binding => binding.$destroy());
47
+ this.bindings.clear();
48
+ (_a = this.freezeExpr) === null || _a === void 0 ? void 0 : _a.$destroy();
49
+ super.$destroy();
50
+ }
51
+ }
52
+ /**
53
+ * A reactive object
54
+ * @class Reactive
55
+ * @extends Destroyable
56
+ */
57
+ export class Reactive extends Destroyable {
58
+ constructor($) {
59
+ super();
60
+ this.$ = $ || new ReactivePrivate;
61
+ }
62
+ /**
63
+ * Create a reference
64
+ * @param value {*} value to reference
65
+ */
66
+ $ref(value) {
67
+ const $ = this.$;
68
+ const ref = new Reference(value);
69
+ $.watch.add(ref);
70
+ return ref;
71
+ }
72
+ /**
73
+ * Create a mirror
74
+ * @param value {IValue} value to mirror
75
+ */
76
+ $mirror(value) {
77
+ const mirror = new Mirror(value, false);
78
+ this.$.watch.add(mirror);
79
+ return mirror;
80
+ }
81
+ /**
82
+ * Create a forward-only mirror
83
+ * @param value {IValue} value to mirror
84
+ */
85
+ $forward(value) {
86
+ const mirror = new Mirror(value, true);
87
+ this.$.watch.add(mirror);
88
+ return mirror;
89
+ }
90
+ /**
91
+ * Creates a pointer
92
+ * @param value {*} default value to point
93
+ * @param forwardOnly {boolean} forward only sync
94
+ */
95
+ $point(value, forwardOnly = false) {
96
+ const $ = this.$;
97
+ const ref = value instanceof IValue ? value : new Reference(value);
98
+ const pointer = new Pointer(ref, forwardOnly);
99
+ // when value is an ivalue will be equal to ref
100
+ if (value !== ref) {
101
+ $.watch.add(ref);
102
+ }
103
+ $.watch.add(pointer);
104
+ return pointer;
105
+ }
106
+ /**
107
+ * Register a model
108
+ * @param model
109
+ */
110
+ $register(model) {
111
+ this.$.models.add(model);
112
+ return model;
113
+ }
114
+ $watch(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
115
+ const $ = this.$;
116
+ $.watch.add(new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9));
117
+ }
118
+ $bind(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
119
+ const res = new Expression(func, !this.$.frozen, v1, v2, v3, v4, v5, v6, v7, v8, v9);
120
+ const $ = this.$;
121
+ $.watch.add(res);
122
+ return res;
123
+ }
124
+ /**
125
+ * Enable reactivity of fields
126
+ */
127
+ $enable() {
128
+ const $ = this.$;
129
+ if (!$.enabled) {
130
+ $.watch.forEach(watcher => {
131
+ watcher.enable();
132
+ });
133
+ $.models.forEach(model => {
134
+ model.enableReactivity();
135
+ });
136
+ $.enabled = true;
137
+ }
138
+ }
139
+ /**
140
+ * Disable reactivity of fields
141
+ */
142
+ $disable() {
143
+ const $ = this.$;
144
+ if ($.enabled) {
145
+ $.watch.forEach(watcher => {
146
+ watcher.disable();
147
+ });
148
+ $.models.forEach(model => {
149
+ model.disableReactivity();
150
+ });
151
+ $.enabled = false;
152
+ }
153
+ }
154
+ /**
155
+ * Disable/Enable reactivity of object fields with feedback
156
+ * @param cond {IValue} show condition
157
+ * @param onOff {function} on show feedback
158
+ * @param onOn {function} on hide feedback
159
+ */
160
+ $bindAlive(cond, onOff, onOn) {
161
+ const $ = this.$;
162
+ if ($.freezeExpr) {
163
+ throw wrongBinding("this component already have a freeze state");
164
+ }
165
+ if ($.watch.has(cond)) {
166
+ throw wrongBinding("freeze state must be bound to an external component");
167
+ }
168
+ $.freezeExpr = new Expression((cond) => {
169
+ $.frozen = !cond;
170
+ if (cond) {
171
+ onOn === null || onOn === void 0 ? void 0 : onOn();
172
+ this.$enable();
173
+ }
174
+ else {
175
+ onOff === null || onOff === void 0 ? void 0 : onOff();
176
+ this.$disable();
177
+ }
178
+ }, true, cond);
179
+ return this;
180
+ }
181
+ $destroy() {
182
+ super.$destroy();
183
+ this.$.$destroy();
184
+ this.$ = null;
185
+ }
186
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Mark an object which can be destroyed
3
+ * @class Destroyable
4
+ */
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
+ /**
40
+ * Garbage collector method
41
+ */
42
+ $destroy() {
43
+ // nothing here
44
+ }
45
+ }
@@ -0,0 +1,16 @@
1
+ const reportIt = "Report it here: https://gitlab.com/vasille-js/vasille-js/-/issues";
2
+ export function notOverwritten() {
3
+ console.error("Vasille-SFP: Internal error", "Must be overwritten", reportIt);
4
+ return "not-overwritten";
5
+ }
6
+ export function internalError(msg) {
7
+ console.error("Vasille-SFP: Internal error", msg, reportIt);
8
+ return "internal-error";
9
+ }
10
+ export function userError(msg, err) {
11
+ console.error("Vasille-SFP: User error", msg);
12
+ return err;
13
+ }
14
+ export function wrongBinding(msg) {
15
+ return userError(msg, "wrong-binding");
16
+ }
@@ -0,0 +1,154 @@
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();
@@ -0,0 +1,56 @@
1
+ import { Destroyable } from "./destroyable.js";
2
+ import { notOverwritten } from "./errors";
3
+ /**
4
+ * Interface which describes a value
5
+ * @class IValue
6
+ * @extends Destroyable
7
+ */
8
+ export class IValue extends Destroyable {
9
+ /**
10
+ * @param isEnabled {boolean} initial is enabled state
11
+ */
12
+ constructor(isEnabled) {
13
+ super();
14
+ this.isEnabled = isEnabled;
15
+ }
16
+ /**
17
+ * Get the encapsulated value
18
+ * @return {*} the encapsulated value
19
+ */
20
+ get $() {
21
+ throw notOverwritten();
22
+ }
23
+ /**
24
+ * Sets the encapsulated value
25
+ * @param value {*} value to encapsulate
26
+ */
27
+ set $(value) {
28
+ throw notOverwritten();
29
+ }
30
+ /**
31
+ * Add a new handler to value change
32
+ * @param handler {function(value : *)} the handler to add
33
+ */
34
+ on(handler) {
35
+ throw notOverwritten();
36
+ }
37
+ /**
38
+ * Removes a handler of value change
39
+ * @param handler {function(value : *)} the handler to remove
40
+ */
41
+ off(handler) {
42
+ throw notOverwritten();
43
+ }
44
+ /**
45
+ * Enable update handlers triggering
46
+ */
47
+ enable() {
48
+ throw notOverwritten();
49
+ }
50
+ /**
51
+ * disable update handlers triggering
52
+ */
53
+ disable() {
54
+ throw notOverwritten();
55
+ }
56
+ }
@@ -0,0 +1,50 @@
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
+ }