@targoninc/jess-components 0.0.15 → 0.0.17

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 (2) hide show
  1. package/dist/index.js +20 -9
  2. 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, updateCallback = () => {}) {
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
- this._callbacks.push(callback);
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
- get onUpdate() {
41
- return this._callbacks;
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) {
@@ -756,6 +765,7 @@ function input(config) {
756
765
  if (config.onchange) {
757
766
  config.onchange(e.target.value);
758
767
  }
768
+ value.value = e.target.value;
759
769
  }).onchange((e) => {
760
770
  touched.value = true;
761
771
  lastChange = Date.now();
@@ -765,6 +775,7 @@ function input(config) {
765
775
  if (config.onchange) {
766
776
  config.onchange(e.target.value);
767
777
  }
778
+ value.value = e.target.value;
768
779
  }).onkeydown(config.onkeydown ?? (() => {})).name(config.name).build(), when(isPassword, eyeButton(toggleState, () => {
769
780
  toggleState.value = !toggleState.value;
770
781
  }))).build(), when(hasError, errorList(errors))).build();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@targoninc/jess-components",
3
3
  "type": "module",
4
- "version": "0.0.15",
4
+ "version": "0.0.17",
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.15"
20
+ "@targoninc/jess": "^0.0.18"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/bun": "latest",