valyrian.js 7.2.11 → 8.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 (165) hide show
  1. package/README.md +6 -6
  2. package/dist/flux-store/index.d.ts +32 -0
  3. package/dist/flux-store/index.d.ts.map +1 -0
  4. package/dist/flux-store/index.js +258 -0
  5. package/dist/flux-store/index.js.map +7 -0
  6. package/dist/flux-store/index.min.js +1 -0
  7. package/dist/flux-store/index.min.js.map +1 -0
  8. package/dist/flux-store/index.mjs +237 -0
  9. package/dist/flux-store/index.mjs.map +7 -0
  10. package/dist/hooks/index.d.ts.map +1 -1
  11. package/dist/hooks/index.js +42 -75
  12. package/dist/hooks/index.js.map +2 -2
  13. package/dist/hooks/index.min.js +1 -0
  14. package/dist/hooks/index.min.js.map +1 -0
  15. package/dist/hooks/index.mjs +43 -76
  16. package/dist/hooks/index.mjs.map +2 -2
  17. package/dist/index.d.ts +52 -54
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +397 -328
  20. package/dist/index.js.map +3 -3
  21. package/dist/index.min.js +1 -1
  22. package/dist/index.min.js.map +1 -1
  23. package/dist/index.mjs +397 -328
  24. package/dist/index.mjs.map +3 -3
  25. package/dist/native-store/index.d.ts +14 -0
  26. package/dist/native-store/index.d.ts.map +1 -0
  27. package/dist/native-store/index.js +103 -0
  28. package/dist/native-store/index.js.map +7 -0
  29. package/dist/native-store/index.min.js +1 -0
  30. package/dist/native-store/index.min.js.map +1 -0
  31. package/dist/native-store/index.mjs +82 -0
  32. package/dist/native-store/index.mjs.map +7 -0
  33. package/dist/node/index.d.ts.map +1 -1
  34. package/dist/node/index.js +223 -86
  35. package/dist/node/index.js.map +4 -4
  36. package/dist/node/index.mjs +223 -86
  37. package/dist/node/index.mjs.map +4 -4
  38. package/dist/node/node.sw.js +152 -0
  39. package/dist/node/utils/inline.d.ts.map +1 -1
  40. package/dist/node/utils/node.sw.js +152 -0
  41. package/dist/node/utils/session-storage.d.ts +22 -0
  42. package/dist/node/utils/session-storage.d.ts.map +1 -0
  43. package/dist/node/utils/sw.d.ts.map +1 -1
  44. package/dist/node/utils/tree-adapter.d.ts +9 -0
  45. package/dist/node/utils/tree-adapter.d.ts.map +1 -1
  46. package/dist/pulse-store/index.d.ts +13 -0
  47. package/dist/pulse-store/index.d.ts.map +1 -0
  48. package/dist/pulse-store/index.js +143 -0
  49. package/dist/pulse-store/index.js.map +7 -0
  50. package/dist/pulse-store/index.min.js +1 -0
  51. package/dist/pulse-store/index.min.js.map +1 -0
  52. package/dist/pulse-store/index.mjs +122 -0
  53. package/dist/pulse-store/index.mjs.map +7 -0
  54. package/dist/request/index.d.ts.map +1 -1
  55. package/dist/request/index.js +68 -89
  56. package/dist/request/index.js.map +2 -2
  57. package/dist/request/index.min.js +1 -0
  58. package/dist/request/index.min.js.map +1 -0
  59. package/dist/request/index.mjs +68 -89
  60. package/dist/request/index.mjs.map +2 -2
  61. package/dist/router/index.d.ts +32 -31
  62. package/dist/router/index.d.ts.map +1 -1
  63. package/dist/router/index.js +256 -104
  64. package/dist/router/index.js.map +3 -3
  65. package/dist/router/index.min.js +1 -0
  66. package/dist/router/index.min.js.map +1 -0
  67. package/dist/router/index.mjs +256 -104
  68. package/dist/router/index.mjs.map +3 -3
  69. package/dist/signals/index.d.ts +6 -0
  70. package/dist/signals/index.d.ts.map +1 -0
  71. package/dist/signals/index.js +92 -0
  72. package/dist/signals/index.js.map +7 -0
  73. package/dist/signals/index.min.js +1 -0
  74. package/dist/signals/index.min.js.map +1 -0
  75. package/dist/signals/index.mjs +71 -0
  76. package/dist/signals/index.mjs.map +7 -0
  77. package/dist/suspense/index.d.ts +6 -0
  78. package/dist/suspense/index.d.ts.map +1 -0
  79. package/dist/suspense/index.js +67 -0
  80. package/dist/suspense/index.js.map +7 -0
  81. package/dist/suspense/index.min.js +1 -0
  82. package/dist/suspense/index.min.js.map +1 -0
  83. package/dist/suspense/index.mjs +46 -0
  84. package/dist/suspense/index.mjs.map +7 -0
  85. package/dist/sw/index.min.js +1 -0
  86. package/dist/sw/index.min.js.map +1 -0
  87. package/dist/translate/index.d.ts +19 -0
  88. package/dist/translate/index.d.ts.map +1 -0
  89. package/dist/translate/index.js +150 -0
  90. package/dist/translate/index.js.map +7 -0
  91. package/dist/translate/index.min.js +1 -0
  92. package/dist/translate/index.min.js.map +1 -0
  93. package/dist/translate/index.mjs +129 -0
  94. package/dist/translate/index.mjs.map +7 -0
  95. package/dist/tsconfig.tsbuildinfo +1 -1
  96. package/dist/utils/deep-freeze.d.ts +3 -0
  97. package/dist/utils/deep-freeze.d.ts.map +1 -0
  98. package/dist/utils/getter-setter.d.ts +3 -0
  99. package/dist/utils/getter-setter.d.ts.map +1 -0
  100. package/dist/utils/has-changed.d.ts +2 -0
  101. package/dist/utils/has-changed.d.ts.map +1 -0
  102. package/dist/utils/index.d.ts +4 -0
  103. package/dist/utils/index.d.ts.map +1 -0
  104. package/dist/utils/index.js +138 -0
  105. package/dist/utils/index.js.map +7 -0
  106. package/dist/utils/index.min.js +1 -0
  107. package/dist/utils/index.min.js.map +1 -0
  108. package/dist/utils/index.mjs +115 -0
  109. package/dist/utils/index.mjs.map +7 -0
  110. package/lib/flux-store/index.ts +301 -0
  111. package/lib/hooks/index.ts +52 -101
  112. package/lib/index.ts +479 -719
  113. package/lib/native-store/index.ts +106 -0
  114. package/lib/node/index.ts +5 -3
  115. package/lib/node/utils/icons.ts +5 -5
  116. package/lib/node/utils/inline.ts +17 -17
  117. package/lib/node/utils/node.sw.js +152 -0
  118. package/lib/node/utils/session-storage.ts +117 -0
  119. package/lib/node/utils/sw.ts +35 -11
  120. package/lib/node/utils/tree-adapter.ts +99 -52
  121. package/lib/pulse-store/index.ts +181 -0
  122. package/lib/request/index.ts +86 -116
  123. package/lib/router/index.ts +358 -170
  124. package/lib/signals/index.ts +98 -0
  125. package/lib/suspense/index.ts +57 -0
  126. package/lib/translate/index.ts +156 -0
  127. package/lib/utils/deep-freeze.ts +54 -0
  128. package/lib/utils/getter-setter.ts +40 -0
  129. package/lib/utils/has-changed.ts +43 -0
  130. package/lib/utils/index.ts +3 -0
  131. package/package.json +38 -50
  132. package/tsconfig.json +1 -1
  133. package/dist/dataset/index.d.ts +0 -24
  134. package/dist/dataset/index.d.ts.map +0 -1
  135. package/dist/dataset/index.js +0 -178
  136. package/dist/dataset/index.js.map +0 -7
  137. package/dist/dataset/index.mjs +0 -157
  138. package/dist/dataset/index.mjs.map +0 -7
  139. package/dist/node/node.sw.tpl +0 -133
  140. package/dist/node/utils/node.sw.tpl +0 -133
  141. package/dist/proxy-signal/index.d.ts +0 -23
  142. package/dist/proxy-signal/index.d.ts.map +0 -1
  143. package/dist/proxy-signal/index.js +0 -138
  144. package/dist/proxy-signal/index.js.map +0 -7
  145. package/dist/proxy-signal/index.mjs +0 -117
  146. package/dist/proxy-signal/index.mjs.map +0 -7
  147. package/dist/signal/index.d.ts +0 -20
  148. package/dist/signal/index.d.ts.map +0 -1
  149. package/dist/signal/index.js +0 -95
  150. package/dist/signal/index.js.map +0 -7
  151. package/dist/signal/index.mjs +0 -74
  152. package/dist/signal/index.mjs.map +0 -7
  153. package/dist/store/index.d.ts +0 -16
  154. package/dist/store/index.d.ts.map +0 -1
  155. package/dist/store/index.js +0 -93
  156. package/dist/store/index.js.map +0 -7
  157. package/dist/store/index.mjs +0 -72
  158. package/dist/store/index.mjs.map +0 -7
  159. package/lib/dataset/index.ts +0 -193
  160. package/lib/index.d.ts +0 -0
  161. package/lib/interfaces.ts.bak +0 -141
  162. package/lib/node/utils/node.sw.tpl +0 -133
  163. package/lib/proxy-signal/index.ts +0 -187
  164. package/lib/signal/index.ts +0 -161
  165. package/lib/store/index.ts +0 -101
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // lib/proxy-signal/index.ts
21
- var proxy_signal_exports = {};
22
- __export(proxy_signal_exports, {
23
- ProxySignal: () => ProxySignal
24
- });
25
- module.exports = __toCommonJS(proxy_signal_exports);
26
- var import_valyrian = require("valyrian.js");
27
- function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
28
- if (typeof cleanup === "function") {
29
- computed.cleanup = cleanup;
30
- }
31
- computed.unsubscribe = () => {
32
- subscriptions.delete(handler);
33
- computed?.cleanup();
34
- };
35
- }
36
- function createSubscription(signal, subscriptions, handler) {
37
- if (subscriptions.has(handler) === false) {
38
- let computed = ProxySignal(() => handler(signal.value));
39
- let cleanup = computed();
40
- makeUnsubscribe(subscriptions, computed, handler, cleanup);
41
- subscriptions.set(handler, computed);
42
- }
43
- return subscriptions.get(handler);
44
- }
45
- var updateTimeout;
46
- function delayedUpdate() {
47
- clearTimeout(updateTimeout);
48
- updateTimeout = setTimeout(import_valyrian.update);
49
- }
50
- function ProxySignal(value) {
51
- let subscriptions = /* @__PURE__ */ new Map();
52
- let getters = {};
53
- let forceUpdate = false;
54
- let signal = new Proxy(
55
- // eslint-disable-next-line no-unused-vars
56
- function(valOrPath, handler) {
57
- if (typeof valOrPath === "undefined") {
58
- return signal.value;
59
- }
60
- if (typeof valOrPath === "function") {
61
- return createSubscription(signal, subscriptions, valOrPath);
62
- }
63
- if (typeof valOrPath === "string" && typeof handler !== "undefined") {
64
- let parsed = valOrPath.split(".");
65
- let result = signal.value;
66
- let next;
67
- while (parsed.length) {
68
- next = parsed.shift();
69
- if (parsed.length > 0) {
70
- if (typeof result[next] !== "object") {
71
- result[next] = {};
72
- }
73
- result = result[next];
74
- } else {
75
- result[next] = typeof handler === "function" ? handler(result[next]) : handler;
76
- }
77
- }
78
- forceUpdate = true;
79
- signal.value = signal.value;
80
- return signal.value;
81
- }
82
- signal.value = valOrPath;
83
- return signal.value;
84
- },
85
- {
86
- set(state, prop, val) {
87
- if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
88
- let old = state[prop];
89
- state[prop] = val;
90
- if (prop === "value" && (forceUpdate || val !== old)) {
91
- forceUpdate = false;
92
- for (let [handler, computed] of subscriptions) {
93
- computed.cleanup();
94
- let cleanup = handler(val);
95
- makeUnsubscribe(subscriptions, computed, handler, cleanup);
96
- }
97
- delayedUpdate();
98
- }
99
- return true;
100
- }
101
- return false;
102
- },
103
- get(state, prop) {
104
- if (prop === "value") {
105
- return typeof state.value === "function" ? state.value() : state.value;
106
- }
107
- if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
108
- return state[prop];
109
- }
110
- if (prop in getters) {
111
- return getters[prop](state.value);
112
- }
113
- }
114
- }
115
- );
116
- Object.defineProperties(signal, {
117
- value: { value, writable: true, enumerable: true },
118
- cleanup: {
119
- value() {
120
- for (let [handler, computed] of subscriptions) {
121
- computed.unsubscribe();
122
- }
123
- },
124
- writable: true,
125
- enumerable: true
126
- },
127
- getter: {
128
- value(name, handler) {
129
- if (name in getters) {
130
- throw new Error("Named computed already exists.");
131
- }
132
- getters[name] = handler;
133
- },
134
- enumerable: true
135
- }
136
- });
137
- return signal;
138
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../lib/proxy-signal/index.ts"],
4
- "sourcesContent": ["import { update } from \"valyrian.js\";\n\n/* eslint-disable no-use-before-define */\ninterface Cleanup {\n (): void;\n}\n\ninterface Subscription {\n // eslint-disable-next-line no-unused-vars\n (value: ProxySignal[\"value\"]): void | Cleanup;\n}\n\ninterface Subscriptions extends Map<Subscription, Cleanup> {}\n\ninterface Getter {\n // eslint-disable-next-line no-unused-vars\n (value: ProxySignal[\"value\"]): any;\n}\n\ninterface Getters {\n [key: string | symbol]: Getter;\n}\n\ninterface ProxySignal {\n // Works as a getter of the value\n (): ProxySignal[\"value\"];\n // Works as a subscription to the value\n // eslint-disable-next-line no-unused-vars\n (value: Subscription): ProxySignal;\n // Works as a setter with a path and a handler\n // eslint-disable-next-line no-unused-vars\n (path: string, handler: (valueAtPathPosition: any) => any): ProxySignal[\"value\"];\n // Works as a setter with a path and a value\n // eslint-disable-next-line no-unused-vars\n (path: string, value: any): ProxySignal[\"value\"];\n // Works as a setter with a value\n // eslint-disable-next-line no-unused-vars\n (value: any): ProxySignal[\"value\"];\n // Gets the current value of the signal.\n value: any;\n // Cleanup function to be called to remove all subscriptions.\n cleanup: () => void;\n // Creates a getter on the signal.\n // eslint-disable-next-line no-unused-vars\n getter: (name: string, handler: Getter) => any;\n // To access the getters on the signal.\n [key: string | number | symbol]: any;\n}\n\nfunction makeUnsubscribe(\n subscriptions: Subscriptions,\n computed: ProxySignal,\n handler: Subscription,\n cleanup?: Cleanup\n) {\n if (typeof cleanup === \"function\") {\n computed.cleanup = cleanup;\n }\n computed.unsubscribe = () => {\n subscriptions.delete(handler);\n computed?.cleanup();\n };\n}\n\nfunction createSubscription(signal: ProxySignal, subscriptions: Subscriptions, handler: Subscription) {\n if (subscriptions.has(handler) === false) {\n // eslint-disable-next-line no-use-before-define\n let computed = ProxySignal(() => handler(signal.value));\n let cleanup = computed(); // Execute to register itself\n makeUnsubscribe(subscriptions, computed, handler, cleanup);\n subscriptions.set(handler, computed);\n }\n\n return subscriptions.get(handler);\n}\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function ProxySignal(value: any): ProxySignal {\n let subscriptions = new Map();\n let getters: Getters = {};\n\n let forceUpdate = false;\n\n let signal: ProxySignal = new Proxy(\n // eslint-disable-next-line no-unused-vars\n function (valOrPath?: any | Subscription, handler?: (valueAtPathPosition: any) => any) {\n // Works as a getter\n if (typeof valOrPath === \"undefined\") {\n return signal.value;\n }\n\n // Works as a subscription\n if (typeof valOrPath === \"function\") {\n return createSubscription(signal, subscriptions, valOrPath);\n }\n\n // Works as a setter with a path\n if (typeof valOrPath === \"string\" && typeof handler !== \"undefined\") {\n let parsed = valOrPath.split(\".\");\n let result = signal.value;\n let next;\n while (parsed.length) {\n next = parsed.shift() as string;\n if (parsed.length > 0) {\n if (typeof result[next] !== \"object\") {\n result[next] = {};\n }\n result = result[next];\n } else {\n result[next] = typeof handler === \"function\" ? handler(result[next]) : handler;\n }\n }\n forceUpdate = true;\n signal.value = signal.value;\n return signal.value;\n }\n\n // Works as a setter with a value\n signal.value = valOrPath;\n return signal.value;\n } as ProxySignal,\n {\n set(state, prop, val) {\n if (prop === \"value\" || prop === \"unsubscribe\" || prop === \"cleanup\") {\n let old = state[prop];\n state[prop] = val;\n if (prop === \"value\" && (forceUpdate || val !== old)) {\n forceUpdate = false;\n for (let [handler, computed] of subscriptions) {\n computed.cleanup();\n let cleanup = handler(val);\n makeUnsubscribe(subscriptions, computed, handler, cleanup);\n }\n delayedUpdate();\n }\n return true;\n }\n return false;\n },\n get(state, prop) {\n if (prop === \"value\") {\n return typeof state.value === \"function\" ? state.value() : state.value;\n }\n\n if (prop === \"cleanup\" || prop === \"unsubscribe\" || prop === \"getter\") {\n return state[prop];\n }\n\n if (prop in getters) {\n return getters[prop](state.value);\n }\n }\n }\n );\n\n Object.defineProperties(signal, {\n value: { value, writable: true, enumerable: true },\n cleanup: {\n value() {\n // eslint-disable-next-line no-unused-vars\n for (let [handler, computed] of subscriptions) {\n computed.unsubscribe();\n }\n },\n writable: true,\n enumerable: true\n },\n getter: {\n value(name: string, handler: Getter) {\n if (name in getters) {\n throw new Error(\"Named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AAe;AAC7C,mBAAS,YAAY;AAAA,QACvB;AAAA,MACF;AAAA,MACA,UAAU;AAAA,MACV,YAAY;AAAA,IACd;AAAA,IACA,QAAQ;AAAA,MACN,MAAM,MAAc,SAAiB;AACnC,YAAI,QAAQ,SAAS;AACnB,gBAAM,IAAI,MAAM,gCAAgC;AAAA,QAClD;AAEA,gBAAQ,IAAI,IAAI;AAAA,MAClB;AAAA,MACA,YAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,117 +0,0 @@
1
- // lib/proxy-signal/index.ts
2
- import { update } from "valyrian.js";
3
- function makeUnsubscribe(subscriptions, computed, handler, cleanup) {
4
- if (typeof cleanup === "function") {
5
- computed.cleanup = cleanup;
6
- }
7
- computed.unsubscribe = () => {
8
- subscriptions.delete(handler);
9
- computed?.cleanup();
10
- };
11
- }
12
- function createSubscription(signal, subscriptions, handler) {
13
- if (subscriptions.has(handler) === false) {
14
- let computed = ProxySignal(() => handler(signal.value));
15
- let cleanup = computed();
16
- makeUnsubscribe(subscriptions, computed, handler, cleanup);
17
- subscriptions.set(handler, computed);
18
- }
19
- return subscriptions.get(handler);
20
- }
21
- var updateTimeout;
22
- function delayedUpdate() {
23
- clearTimeout(updateTimeout);
24
- updateTimeout = setTimeout(update);
25
- }
26
- function ProxySignal(value) {
27
- let subscriptions = /* @__PURE__ */ new Map();
28
- let getters = {};
29
- let forceUpdate = false;
30
- let signal = new Proxy(
31
- // eslint-disable-next-line no-unused-vars
32
- function(valOrPath, handler) {
33
- if (typeof valOrPath === "undefined") {
34
- return signal.value;
35
- }
36
- if (typeof valOrPath === "function") {
37
- return createSubscription(signal, subscriptions, valOrPath);
38
- }
39
- if (typeof valOrPath === "string" && typeof handler !== "undefined") {
40
- let parsed = valOrPath.split(".");
41
- let result = signal.value;
42
- let next;
43
- while (parsed.length) {
44
- next = parsed.shift();
45
- if (parsed.length > 0) {
46
- if (typeof result[next] !== "object") {
47
- result[next] = {};
48
- }
49
- result = result[next];
50
- } else {
51
- result[next] = typeof handler === "function" ? handler(result[next]) : handler;
52
- }
53
- }
54
- forceUpdate = true;
55
- signal.value = signal.value;
56
- return signal.value;
57
- }
58
- signal.value = valOrPath;
59
- return signal.value;
60
- },
61
- {
62
- set(state, prop, val) {
63
- if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
64
- let old = state[prop];
65
- state[prop] = val;
66
- if (prop === "value" && (forceUpdate || val !== old)) {
67
- forceUpdate = false;
68
- for (let [handler, computed] of subscriptions) {
69
- computed.cleanup();
70
- let cleanup = handler(val);
71
- makeUnsubscribe(subscriptions, computed, handler, cleanup);
72
- }
73
- delayedUpdate();
74
- }
75
- return true;
76
- }
77
- return false;
78
- },
79
- get(state, prop) {
80
- if (prop === "value") {
81
- return typeof state.value === "function" ? state.value() : state.value;
82
- }
83
- if (prop === "cleanup" || prop === "unsubscribe" || prop === "getter") {
84
- return state[prop];
85
- }
86
- if (prop in getters) {
87
- return getters[prop](state.value);
88
- }
89
- }
90
- }
91
- );
92
- Object.defineProperties(signal, {
93
- value: { value, writable: true, enumerable: true },
94
- cleanup: {
95
- value() {
96
- for (let [handler, computed] of subscriptions) {
97
- computed.unsubscribe();
98
- }
99
- },
100
- writable: true,
101
- enumerable: true
102
- },
103
- getter: {
104
- value(name, handler) {
105
- if (name in getters) {
106
- throw new Error("Named computed already exists.");
107
- }
108
- getters[name] = handler;
109
- },
110
- enumerable: true
111
- }
112
- });
113
- return signal;
114
- }
115
- export {
116
- ProxySignal
117
- };
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../lib/proxy-signal/index.ts"],
4
- "sourcesContent": ["import { update } from \"valyrian.js\";\n\n/* eslint-disable no-use-before-define */\ninterface Cleanup {\n (): void;\n}\n\ninterface Subscription {\n // eslint-disable-next-line no-unused-vars\n (value: ProxySignal[\"value\"]): void | Cleanup;\n}\n\ninterface Subscriptions extends Map<Subscription, Cleanup> {}\n\ninterface Getter {\n // eslint-disable-next-line no-unused-vars\n (value: ProxySignal[\"value\"]): any;\n}\n\ninterface Getters {\n [key: string | symbol]: Getter;\n}\n\ninterface ProxySignal {\n // Works as a getter of the value\n (): ProxySignal[\"value\"];\n // Works as a subscription to the value\n // eslint-disable-next-line no-unused-vars\n (value: Subscription): ProxySignal;\n // Works as a setter with a path and a handler\n // eslint-disable-next-line no-unused-vars\n (path: string, handler: (valueAtPathPosition: any) => any): ProxySignal[\"value\"];\n // Works as a setter with a path and a value\n // eslint-disable-next-line no-unused-vars\n (path: string, value: any): ProxySignal[\"value\"];\n // Works as a setter with a value\n // eslint-disable-next-line no-unused-vars\n (value: any): ProxySignal[\"value\"];\n // Gets the current value of the signal.\n value: any;\n // Cleanup function to be called to remove all subscriptions.\n cleanup: () => void;\n // Creates a getter on the signal.\n // eslint-disable-next-line no-unused-vars\n getter: (name: string, handler: Getter) => any;\n // To access the getters on the signal.\n [key: string | number | symbol]: any;\n}\n\nfunction makeUnsubscribe(\n subscriptions: Subscriptions,\n computed: ProxySignal,\n handler: Subscription,\n cleanup?: Cleanup\n) {\n if (typeof cleanup === \"function\") {\n computed.cleanup = cleanup;\n }\n computed.unsubscribe = () => {\n subscriptions.delete(handler);\n computed?.cleanup();\n };\n}\n\nfunction createSubscription(signal: ProxySignal, subscriptions: Subscriptions, handler: Subscription) {\n if (subscriptions.has(handler) === false) {\n // eslint-disable-next-line no-use-before-define\n let computed = ProxySignal(() => handler(signal.value));\n let cleanup = computed(); // Execute to register itself\n makeUnsubscribe(subscriptions, computed, handler, cleanup);\n subscriptions.set(handler, computed);\n }\n\n return subscriptions.get(handler);\n}\n\nlet updateTimeout: any;\nfunction delayedUpdate() {\n clearTimeout(updateTimeout);\n updateTimeout = setTimeout(update);\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function ProxySignal(value: any): ProxySignal {\n let subscriptions = new Map();\n let getters: Getters = {};\n\n let forceUpdate = false;\n\n let signal: ProxySignal = new Proxy(\n // eslint-disable-next-line no-unused-vars\n function (valOrPath?: any | Subscription, handler?: (valueAtPathPosition: any) => any) {\n // Works as a getter\n if (typeof valOrPath === \"undefined\") {\n return signal.value;\n }\n\n // Works as a subscription\n if (typeof valOrPath === \"function\") {\n return createSubscription(signal, subscriptions, valOrPath);\n }\n\n // Works as a setter with a path\n if (typeof valOrPath === \"string\" && typeof handler !== \"undefined\") {\n let parsed = valOrPath.split(\".\");\n let result = signal.value;\n let next;\n while (parsed.length) {\n next = parsed.shift() as string;\n if (parsed.length > 0) {\n if (typeof result[next] !== \"object\") {\n result[next] = {};\n }\n result = result[next];\n } else {\n result[next] = typeof handler === \"function\" ? handler(result[next]) : handler;\n }\n }\n forceUpdate = true;\n signal.value = signal.value;\n return signal.value;\n }\n\n // Works as a setter with a value\n signal.value = valOrPath;\n return signal.value;\n } as ProxySignal,\n {\n set(state, prop, val) {\n if (prop === \"value\" || prop === \"unsubscribe\" || prop === \"cleanup\") {\n let old = state[prop];\n state[prop] = val;\n if (prop === \"value\" && (forceUpdate || val !== old)) {\n forceUpdate = false;\n for (let [handler, computed] of subscriptions) {\n computed.cleanup();\n let cleanup = handler(val);\n makeUnsubscribe(subscriptions, computed, handler, cleanup);\n }\n delayedUpdate();\n }\n return true;\n }\n return false;\n },\n get(state, prop) {\n if (prop === \"value\") {\n return typeof state.value === \"function\" ? state.value() : state.value;\n }\n\n if (prop === \"cleanup\" || prop === \"unsubscribe\" || prop === \"getter\") {\n return state[prop];\n }\n\n if (prop in getters) {\n return getters[prop](state.value);\n }\n }\n }\n );\n\n Object.defineProperties(signal, {\n value: { value, writable: true, enumerable: true },\n cleanup: {\n value() {\n // eslint-disable-next-line no-unused-vars\n for (let [handler, computed] of subscriptions) {\n computed.unsubscribe();\n }\n },\n writable: true,\n enumerable: true\n },\n getter: {\n value(name: string, handler: Getter) {\n if (name in getters) {\n throw new Error(\"Named computed already exists.\");\n }\n\n getters[name] = handler;\n },\n enumerable: true\n }\n });\n\n return signal;\n}\n"],
5
- "mappings":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AAc,SAAiB;AACnC,YAAI,QAAQ,SAAS;AACnB,gBAAM,IAAI,MAAM,gCAAgC;AAAA,QAClD;AAEA,gBAAQ,IAAI,IAAI;AAAA,MAClB;AAAA,MACA,YAAY;AAAA,IACd;AAAA,EACF,CAAC;AAED,SAAO;AACT;",
6
- "names": []
7
- }
@@ -1,20 +0,0 @@
1
- interface GetterInterface {
2
- (): any;
3
- }
4
- interface SetterInterface {
5
- (value: any): void;
6
- }
7
- interface SubscribeInterface {
8
- (callback: Function): void;
9
- }
10
- interface SubscriptionsInterface extends Array<Function> {
11
- }
12
- export interface SignalInterface extends Array<any> {
13
- 0: GetterInterface;
14
- 1: SetterInterface;
15
- 2: SubscribeInterface;
16
- 3: SubscriptionsInterface;
17
- }
18
- export declare function Signal(initialValue: any): SignalInterface;
19
- export {};
20
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signal/index.ts"],"names":[],"mappings":"AAEA,UAAU,eAAe;IACvB,IAAI,GAAG,CAAC;CACT;AAED,UAAU,eAAe;IACvB,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAC;CACpB;AAED,UAAU,kBAAkB;IAC1B,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;CAC5B;AAED,UAAU,sBAAuB,SAAQ,KAAK,CAAC,QAAQ,CAAC;CAAG;AAE3D,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,GAAG,CAAC;IACjD,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,eAAe,CAAC;IACnB,CAAC,EAAE,kBAAkB,CAAC;IACtB,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAGD,wBAAgB,MAAM,CAAC,YAAY,EAAE,GAAG,GAAG,eAAe,CAwIzD"}
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // lib/signal/index.ts
21
- var signal_exports = {};
22
- __export(signal_exports, {
23
- Signal: () => Signal
24
- });
25
- module.exports = __toCommonJS(signal_exports);
26
- var import_valyrian = require("valyrian.js");
27
- function Signal(initialValue) {
28
- const { vnode, component } = { ...import_valyrian.current };
29
- if (vnode && component) {
30
- if (!vnode.components) {
31
- vnode.components = [];
32
- }
33
- if (vnode.components.indexOf(component) === -1) {
34
- vnode.signal_calls = -1;
35
- vnode.components.push(component);
36
- if (!component.signals) {
37
- component.signals = [];
38
- (0, import_valyrian.onUnmount)(() => Reflect.deleteProperty(component, "signals"));
39
- }
40
- }
41
- let signal2 = component.signals[++vnode.signal_calls];
42
- if (signal2) {
43
- signal2[3].length = 0;
44
- return signal2;
45
- }
46
- }
47
- let value = initialValue;
48
- const subscriptions = [];
49
- const subscribe = (callback) => {
50
- if (subscriptions.indexOf(callback) === -1) {
51
- subscriptions.push(callback);
52
- }
53
- };
54
- let vnodesToUpdate = [];
55
- const updateVnodes = () => {
56
- let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode2, index, self) => {
57
- return self.findIndex((v2) => v2.dom === vnode2.dom) === index;
58
- });
59
- for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {
60
- const vnode2 = vnodesToUpdateCopy[i];
61
- let newVnode = (0, import_valyrian.v)(vnode2.tag, vnode2.props, ...vnode2.initialChildren);
62
- newVnode.dom = vnode2.dom;
63
- newVnode.isSVG = vnode2.isSVG;
64
- (0, import_valyrian.updateVnode)(newVnode, vnode2);
65
- }
66
- };
67
- function get() {
68
- const { vnode: vnode2 } = import_valyrian.current;
69
- if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {
70
- if (!vnode2.initialChildren) {
71
- vnode2.initialChildren = [...vnode2.children];
72
- }
73
- vnodesToUpdate.push(vnode2);
74
- subscribe(updateVnodes);
75
- }
76
- return value;
77
- }
78
- const set = (newValue) => {
79
- if (import_valyrian.current.event) {
80
- import_valyrian.current.event.preventDefault();
81
- }
82
- if (newValue === value) {
83
- return;
84
- }
85
- value = newValue;
86
- for (let i = 0, l = subscriptions.length; i < l; i++) {
87
- subscriptions[i](value);
88
- }
89
- };
90
- let signal = [get, set, subscribe, subscriptions];
91
- if (vnode && component) {
92
- component.signals.push(signal);
93
- }
94
- return signal;
95
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../lib/signal/index.ts"],
4
- "sourcesContent": ["import { VnodeWithDom, current, onUnmount, updateVnode, v } from \"valyrian.js\";\n\ninterface GetterInterface {\n (): any;\n}\n\ninterface SetterInterface {\n (value: any): void;\n}\n\ninterface SubscribeInterface {\n (callback: Function): void;\n}\n\ninterface SubscriptionsInterface extends Array<Function> {}\n\nexport interface SignalInterface extends Array<any> {\n 0: GetterInterface;\n 1: SetterInterface;\n 2: SubscribeInterface;\n 3: SubscriptionsInterface;\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function Signal(initialValue: any): SignalInterface {\n // Create a copy of the current context object\n const { vnode, component } = { ...current };\n\n // Check if the context object has a vnode property\n if (vnode && component) {\n // Is first call\n if (!vnode.components) {\n // Set the components property to an empty array\n vnode.components = [];\n }\n\n // Check if the components array of the vnode object does not contain the component object\n if (vnode.components.indexOf(component) === -1) {\n // Set the calls property to -1\n vnode.signal_calls = -1;\n // Add the component to the components array\n vnode.components.push(component);\n\n // Check if the component object has a signals property\n if (!component.signals) {\n // Set the signals property of the component object to an empty array\n component.signals = [];\n // Add a function to the cleanup stack that removes the signals property from the component object\n onUnmount(() => Reflect.deleteProperty(component, \"signals\"));\n }\n }\n\n // Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array\n let signal: SignalInterface = component.signals[++vnode.signal_calls];\n\n // If a signal has already been assigned to the signal variable, return it\n if (signal) {\n // Remove all subscriptions because we come from a new render\n signal[3].length = 0;\n\n // Return the signal\n return signal;\n }\n }\n\n // Declare a variable to store the current value of the Signal\n let value = initialValue;\n\n // Create an array to store functions that have subscribed to changes to the Signal's value\n const subscriptions: SubscriptionsInterface = [];\n\n // Define a function that allows other parts of the code to subscribe to changes to the Signal's value\n const subscribe = (callback: Function) => {\n // Add the callback function to the subscriptions array if it is not already in the array\n if (subscriptions.indexOf(callback) === -1) {\n subscriptions.push(callback);\n }\n };\n\n // Set the vnodes to update when the Signal's value changes\n let vnodesToUpdate: Array<VnodeWithDom> = [];\n\n // This is the function that will be called when the Signal's value changes\n const updateVnodes = () => {\n // Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes\n let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {\n return self.findIndex((v) => v.dom === vnode.dom) === index;\n });\n\n // Loop through the vnodesToUpdate array\n for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {\n const vnode2 = vnodesToUpdateCopy[i];\n // If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties\n let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;\n newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property\n newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property\n\n // Update the vnode object\n updateVnode(newVnode, vnode2);\n }\n };\n\n // Define a function that returns the current value of the Signal\n function get() {\n // Get the current vnode from the context object\n const { vnode: vnode2 } = current;\n\n // If we have a current vnode, it means that a get function is being called from within a component\n // so we subscribe the vnode to be updated when the Signal's value changes\n if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {\n // We set the initialChildren to a copy of the vnode's children array\n // This is the case when the vnode is a component that has not been rendered yet and we need the initial children\n // because they could have the components that are using the Signal\n if (!vnode2.initialChildren) {\n vnode2.initialChildren = [...vnode2.children];\n }\n\n // Add the vnode to the vnodesToUpdate array\n vnodesToUpdate.push(vnode2);\n\n // Subscribe the updateVnodes function to the Signal\n subscribe(updateVnodes);\n }\n\n // Return the current value of the Signal\n return value;\n }\n\n // Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change\n const set = (newValue: any) => {\n // If we have a current event on going, prevent the default action\n if (current.event) {\n current.event.preventDefault();\n }\n\n // Just return if the new value is the same as the current value\n if (newValue === value) {\n return;\n }\n\n // Update the value of the Signal\n value = newValue;\n\n // Call each subscribed function with the new value of the Signal as an argument\n for (let i = 0, l = subscriptions.length; i < l; i++) {\n subscriptions[i](value);\n }\n };\n\n // Assign the signal variable an array containing the get, set, and subscribe functions\n let signal: SignalInterface = [get, set, subscribe, subscriptions];\n\n // If the context object has a vnode property, add the signal to the vnode's signals array\n // and add the subscriptions array to the vnode's subscriptions array\n if (vnode && component) {\n component.signals.push(signal);\n }\n\n // Return the signal\n return signal;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAiE;AAwB1D,SAAS,OAAO,cAAoC;AAEzD,QAAM,EAAE,OAAO,UAAU,IAAI,EAAE,GAAG,wBAAQ;AAG1C,MAAI,SAAS,WAAW;AAEtB,QAAI,CAAC,MAAM,YAAY;AAErB,YAAM,aAAa,CAAC;AAAA,IACtB;AAGA,QAAI,MAAM,WAAW,QAAQ,SAAS,MAAM,IAAI;AAE9C,YAAM,eAAe;AAErB,YAAM,WAAW,KAAK,SAAS;AAG/B,UAAI,CAAC,UAAU,SAAS;AAEtB,kBAAU,UAAU,CAA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C/B;AAGA,QAAI,aAAa,OAAO;AACtB;AAAA,IACF;AAGA,YAAQ;AAGR,aAAS,IAAI,GAAG,IAAI,cAAc,QAAQ,IAAI,GAAG,KAAK;AACpD,oBAAc,CAAC,EAAE,KAAK;AAAA,IACxB;AAAA,EACF;AAGA,MAAI,SAA0B,CAAC,KAAK,KAAK,WAAW,aAAa;AAIjE,MAAI,SAAS,WAAW;AACtB,cAAU,QAAQ,KAAK,MAAM;AAAA,EAC/B;AAGA,SAAO;AACT;",
6
- "names": ["signal", "vnode", "v"]
7
- }
@@ -1,74 +0,0 @@
1
- // lib/signal/index.ts
2
- import { current, onUnmount, updateVnode, v } from "valyrian.js";
3
- function Signal(initialValue) {
4
- const { vnode, component } = { ...current };
5
- if (vnode && component) {
6
- if (!vnode.components) {
7
- vnode.components = [];
8
- }
9
- if (vnode.components.indexOf(component) === -1) {
10
- vnode.signal_calls = -1;
11
- vnode.components.push(component);
12
- if (!component.signals) {
13
- component.signals = [];
14
- onUnmount(() => Reflect.deleteProperty(component, "signals"));
15
- }
16
- }
17
- let signal2 = component.signals[++vnode.signal_calls];
18
- if (signal2) {
19
- signal2[3].length = 0;
20
- return signal2;
21
- }
22
- }
23
- let value = initialValue;
24
- const subscriptions = [];
25
- const subscribe = (callback) => {
26
- if (subscriptions.indexOf(callback) === -1) {
27
- subscriptions.push(callback);
28
- }
29
- };
30
- let vnodesToUpdate = [];
31
- const updateVnodes = () => {
32
- let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode2, index, self) => {
33
- return self.findIndex((v2) => v2.dom === vnode2.dom) === index;
34
- });
35
- for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {
36
- const vnode2 = vnodesToUpdateCopy[i];
37
- let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren);
38
- newVnode.dom = vnode2.dom;
39
- newVnode.isSVG = vnode2.isSVG;
40
- updateVnode(newVnode, vnode2);
41
- }
42
- };
43
- function get() {
44
- const { vnode: vnode2 } = current;
45
- if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {
46
- if (!vnode2.initialChildren) {
47
- vnode2.initialChildren = [...vnode2.children];
48
- }
49
- vnodesToUpdate.push(vnode2);
50
- subscribe(updateVnodes);
51
- }
52
- return value;
53
- }
54
- const set = (newValue) => {
55
- if (current.event) {
56
- current.event.preventDefault();
57
- }
58
- if (newValue === value) {
59
- return;
60
- }
61
- value = newValue;
62
- for (let i = 0, l = subscriptions.length; i < l; i++) {
63
- subscriptions[i](value);
64
- }
65
- };
66
- let signal = [get, set, subscribe, subscriptions];
67
- if (vnode && component) {
68
- component.signals.push(signal);
69
- }
70
- return signal;
71
- }
72
- export {
73
- Signal
74
- };
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../lib/signal/index.ts"],
4
- "sourcesContent": ["import { VnodeWithDom, current, onUnmount, updateVnode, v } from \"valyrian.js\";\n\ninterface GetterInterface {\n (): any;\n}\n\ninterface SetterInterface {\n (value: any): void;\n}\n\ninterface SubscribeInterface {\n (callback: Function): void;\n}\n\ninterface SubscriptionsInterface extends Array<Function> {}\n\nexport interface SignalInterface extends Array<any> {\n 0: GetterInterface;\n 1: SetterInterface;\n 2: SubscribeInterface;\n 3: SubscriptionsInterface;\n}\n\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport function Signal(initialValue: any): SignalInterface {\n // Create a copy of the current context object\n const { vnode, component } = { ...current };\n\n // Check if the context object has a vnode property\n if (vnode && component) {\n // Is first call\n if (!vnode.components) {\n // Set the components property to an empty array\n vnode.components = [];\n }\n\n // Check if the components array of the vnode object does not contain the component object\n if (vnode.components.indexOf(component) === -1) {\n // Set the calls property to -1\n vnode.signal_calls = -1;\n // Add the component to the components array\n vnode.components.push(component);\n\n // Check if the component object has a signals property\n if (!component.signals) {\n // Set the signals property of the component object to an empty array\n component.signals = [];\n // Add a function to the cleanup stack that removes the signals property from the component object\n onUnmount(() => Reflect.deleteProperty(component, \"signals\"));\n }\n }\n\n // Assign the signal variable to the signal stored at the index of the vnode object's calls property in the vnode's signals array\n let signal: SignalInterface = component.signals[++vnode.signal_calls];\n\n // If a signal has already been assigned to the signal variable, return it\n if (signal) {\n // Remove all subscriptions because we come from a new render\n signal[3].length = 0;\n\n // Return the signal\n return signal;\n }\n }\n\n // Declare a variable to store the current value of the Signal\n let value = initialValue;\n\n // Create an array to store functions that have subscribed to changes to the Signal's value\n const subscriptions: SubscriptionsInterface = [];\n\n // Define a function that allows other parts of the code to subscribe to changes to the Signal's value\n const subscribe = (callback: Function) => {\n // Add the callback function to the subscriptions array if it is not already in the array\n if (subscriptions.indexOf(callback) === -1) {\n subscriptions.push(callback);\n }\n };\n\n // Set the vnodes to update when the Signal's value changes\n let vnodesToUpdate: Array<VnodeWithDom> = [];\n\n // This is the function that will be called when the Signal's value changes\n const updateVnodes = () => {\n // Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes\n let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {\n return self.findIndex((v) => v.dom === vnode.dom) === index;\n });\n\n // Loop through the vnodesToUpdate array\n for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {\n const vnode2 = vnodesToUpdateCopy[i];\n // If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties\n let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;\n newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property\n newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property\n\n // Update the vnode object\n updateVnode(newVnode, vnode2);\n }\n };\n\n // Define a function that returns the current value of the Signal\n function get() {\n // Get the current vnode from the context object\n const { vnode: vnode2 } = current;\n\n // If we have a current vnode, it means that a get function is being called from within a component\n // so we subscribe the vnode to be updated when the Signal's value changes\n if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {\n // We set the initialChildren to a copy of the vnode's children array\n // This is the case when the vnode is a component that has not been rendered yet and we need the initial children\n // because they could have the components that are using the Signal\n if (!vnode2.initialChildren) {\n vnode2.initialChildren = [...vnode2.children];\n }\n\n // Add the vnode to the vnodesToUpdate array\n vnodesToUpdate.push(vnode2);\n\n // Subscribe the updateVnodes function to the Signal\n subscribe(updateVnodes);\n }\n\n // Return the current value of the Signal\n return value;\n }\n\n // Define a function that allows the value of the Signal to be updated and notifies any subscribed functions of the change\n const set = (newValue: any) => {\n // If we have a current event on going, prevent the default action\n if (current.event) {\n current.event.preventDefault();\n }\n\n // Just return if the new value is the same as the current value\n if (newValue === value) {\n return;\n }\n\n // Update the value of the Signal\n value = newValue;\n\n // Call each subscribed function with the new value of the Signal as an argument\n for (let i = 0, l = subscriptions.length; i < l; i++) {\n subscriptions[i](value);\n }\n };\n\n // Assign the signal variable an array containing the get, set, and subscribe functions\n let signal: SignalInterface = [get, set, subscribe, subscriptions];\n\n // If the context object has a vnode property, add the signal to the vnode's signals array\n // and add the subscriptions array to the vnode's subscriptions array\n if (vnode && component) {\n component.signals.push(signal);\n }\n\n // Return the signal\n return signal;\n}\n"],
5
- "mappings": ";AAAA,SAAuB,SAAS,WAAW,aAAa,SAAS;AAwB1D,SAAS,OAAO,cAAoC;AAEzD,QAAM,EAAE,OAAO,UAAU,IAAI,EAAE,GAAG,QAAQ;AAG1C,MAAI,SAAS,WAAW;AAEtB,QAAI,CAAC,MAAM,YAAY;AAErB,YAAM,aAAa,CAAC;AAAA,IACtB;AAGA,QAAI,MAAM,WAAW,QAAQ,SAAS,MAAM,IAAI;AAE9C,YAAM,eAAe;AAErB,YAAM,WAAW,KAAK,SAAS;AAG/B,UAAI,CAAC,UAAU,SAAS;AAEtB,kBAAU,UAAU,CAAC;AAErB,kBAAU,MAAM,QAAQ,eAAe,WAAW,SAAS,CAAC;AAAA,MAC9D;AAAA,IACF;AAGA,QAAIA,UAA0B,UAAU,QAAQ,EAAE,MAAM,YAAY;AAGpE,QAAIA,SAAQ;AAEV,MAAAA,QAAO,CAAC,EAAE,SAAS;AA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CAAC,KAAK,KAAK,WAAW,aAAa;AAIjE,MAAI,SAAS,WAAW;AACtB,cAAU,QAAQ,KAAK,MAAM;AAAA,EAC/B;AAGA,SAAO;AACT;",
6
- "names": ["signal", "vnode", "v"]
7
- }
@@ -1,16 +0,0 @@
1
- interface StoreOptions {
2
- state?: Record<string, unknown> | (() => Record<string, unknown>);
3
- getters?: Record<string, Function>;
4
- mutations?: Record<string, Function>;
5
- actions?: Record<string, Function>;
6
- }
7
- interface StoreInstance {
8
- new (options: StoreOptions): StoreInstance;
9
- state: Record<string, any>;
10
- getters?: Record<string, any>;
11
- commit: (type: string, ...payload: any[]) => void;
12
- dispatch: (type: string, ...payload: any[]) => void;
13
- }
14
- export declare const Store: StoreInstance;
15
- export {};
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/store/index.ts"],"names":[],"mappings":"AAEA,UAAU,YAAY;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAClE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACpC;AAED,UAAU,aAAa;IAErB,KAAK,OAAO,EAAE,YAAY,GAAG,aAAa,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE9B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAElD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACrD;AAgCD,eAAO,MAAM,KAAK,eAkDW,CAAC"}
@@ -1,93 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // lib/store/index.ts
21
- var store_exports = {};
22
- __export(store_exports, {
23
- Store: () => Store
24
- });
25
- module.exports = __toCommonJS(store_exports);
26
- var import_valyrian = require("valyrian.js");
27
- function keyExists(typeOfKey, object, key) {
28
- if (key in object === false) {
29
- throw new Error(`The ${typeOfKey} "${key}" does not exists.`);
30
- }
31
- }
32
- function deepFreeze(obj) {
33
- if (typeof obj === "object" && obj !== null && !Object.isFrozen(obj)) {
34
- if (Array.isArray(obj)) {
35
- for (let i = 0, l = obj.length; i < l; i++) {
36
- deepFreeze(obj[i]);
37
- }
38
- } else {
39
- let props = Reflect.ownKeys(obj);
40
- for (let i = 0, l = props.length; i < l; i++) {
41
- deepFreeze(obj[props[i]]);
42
- }
43
- }
44
- Object.freeze(obj);
45
- }
46
- return obj;
47
- }
48
- var updateTimeout;
49
- function delayedUpdate() {
50
- clearTimeout(updateTimeout);
51
- updateTimeout = setTimeout(import_valyrian.update);
52
- }
53
- var Store = function Store2({ state = {}, getters = {}, actions = {}, mutations = {} } = {}) {
54
- let frozen = true;
55
- function isUnfrozen() {
56
- if (frozen) {
57
- throw new Error("You need to commit a mutation to change the state");
58
- }
59
- }
60
- let localState = typeof state === "function" ? state() : state;
61
- this.state = new Proxy(localState || {}, {
62
- get: (state2, prop) => deepFreeze(state2[prop]),
63
- set: (state2, prop, value) => {
64
- isUnfrozen();
65
- state2[prop] = value;
66
- return true;
67
- },
68
- deleteProperty: (state2, prop) => {
69
- isUnfrozen();
70
- Reflect.deleteProperty(state2, prop);
71
- return true;
72
- }
73
- });
74
- this.getters = new Proxy(getters, {
75
- get: (getters2, getter) => {
76
- try {
77
- return getters2[getter](this.state, this.getters);
78
- } catch (e) {
79
- }
80
- }
81
- });
82
- this.commit = (mutation, ...args) => {
83
- keyExists("mutation", mutations, mutation);
84
- frozen = false;
85
- mutations[mutation](this.state, ...args);
86
- frozen = true;
87
- delayedUpdate();
88
- };
89
- this.dispatch = (action, ...args) => {
90
- keyExists("action", actions, action);
91
- return Promise.resolve(actions[action](this, ...args));
92
- };
93
- };