@targoninc/jess-components 0.0.16 → 0.0.18
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/dist/index.js +22 -13
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
// node_modules/@targoninc/jess/dist/index.js
|
|
3
3
|
class Signal {
|
|
4
4
|
_callbacks = [];
|
|
5
|
+
_keyCallbacks = new Map;
|
|
5
6
|
_value;
|
|
6
7
|
_values = {};
|
|
7
8
|
type = "jess-signal";
|
|
8
|
-
constructor(initialValue
|
|
9
|
+
constructor(initialValue) {
|
|
9
10
|
this._value = initialValue;
|
|
10
11
|
this._values = {};
|
|
11
|
-
this._callbacks.push(updateCallback);
|
|
12
12
|
}
|
|
13
13
|
boolValues(assignments = {}) {
|
|
14
14
|
for (let key in assignments) {
|
|
@@ -28,20 +28,26 @@ class Signal {
|
|
|
28
28
|
unsubscribeAll() {
|
|
29
29
|
this._callbacks = [];
|
|
30
30
|
}
|
|
31
|
-
subscribe(callback) {
|
|
32
|
-
|
|
31
|
+
subscribe(callback, key) {
|
|
32
|
+
if (key !== undefined && key !== null) {
|
|
33
|
+
this._keyCallbacks.set(key, callback);
|
|
34
|
+
} else {
|
|
35
|
+
this._callbacks.push(callback);
|
|
36
|
+
}
|
|
33
37
|
}
|
|
34
38
|
unsubscribe(callback) {
|
|
35
39
|
const index = this._callbacks.indexOf(callback);
|
|
36
40
|
if (index >= 0) {
|
|
37
41
|
this._callbacks.splice(index, 1);
|
|
38
42
|
}
|
|
43
|
+
for (const [key, func] of Object.entries(this._keyCallbacks)) {
|
|
44
|
+
if (func === callback) {
|
|
45
|
+
this.unsubscribeKey(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
set onUpdate(callback) {
|
|
44
|
-
this._callbacks.push(callback);
|
|
49
|
+
unsubscribeKey(key) {
|
|
50
|
+
this._keyCallbacks.delete(key);
|
|
45
51
|
}
|
|
46
52
|
get value() {
|
|
47
53
|
return this._value;
|
|
@@ -50,6 +56,9 @@ class Signal {
|
|
|
50
56
|
const changed = this._value !== value;
|
|
51
57
|
this._value = value;
|
|
52
58
|
this._callbacks.forEach((callback) => callback(value, changed));
|
|
59
|
+
for (const [_, callback] of this._keyCallbacks.entries()) {
|
|
60
|
+
callback(value, changed);
|
|
61
|
+
}
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
function signal(initialValue) {
|
|
@@ -199,9 +208,9 @@ class DomNode {
|
|
|
199
208
|
const value = arguments[i + 1];
|
|
200
209
|
if (value && isSignal(value)) {
|
|
201
210
|
this._node.setAttribute(key, value.value);
|
|
202
|
-
value.
|
|
211
|
+
value.subscribe((newValue) => {
|
|
203
212
|
this._node.setAttribute(key, newValue);
|
|
204
|
-
};
|
|
213
|
+
});
|
|
205
214
|
} else {
|
|
206
215
|
this._node.setAttribute(key, value);
|
|
207
216
|
}
|
|
@@ -556,9 +565,9 @@ class DomNode {
|
|
|
556
565
|
}
|
|
557
566
|
if (value && isSignal(value)) {
|
|
558
567
|
this._node.style[key] = value.value;
|
|
559
|
-
value.
|
|
568
|
+
value.subscribe((newValue) => {
|
|
560
569
|
this._node.style[key] = newValue;
|
|
561
|
-
};
|
|
570
|
+
});
|
|
562
571
|
} else {
|
|
563
572
|
this._node.style[key] = value;
|
|
564
573
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targoninc/jess-components",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.18",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"prepublishOnly": "bun run build"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@targoninc/jess": "^0.0.
|
|
20
|
+
"@targoninc/jess": "^0.0.19"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/bun": "latest",
|