valyrian.js 7.2.11 → 7.2.12
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/dataset/index.d.ts +2 -2
- package/dist/dataset/index.d.ts.map +1 -1
- package/dist/dataset/index.js +21 -21
- package/dist/dataset/index.js.map +2 -2
- package/dist/dataset/index.mjs +22 -22
- package/dist/dataset/index.mjs.map +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +17 -32
- package/dist/hooks/index.js.map +3 -3
- package/dist/hooks/index.mjs +17 -32
- package/dist/hooks/index.mjs.map +3 -3
- package/dist/index.d.ts +49 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -326
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +378 -326
- package/dist/index.mjs.map +3 -3
- package/dist/node/index.js +101 -78
- package/dist/node/index.js.map +2 -2
- package/dist/node/index.mjs +101 -78
- package/dist/node/index.mjs.map +2 -2
- package/dist/node/utils/tree-adapter.d.ts +5 -0
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/proxy-signal/index.js +10 -10
- package/dist/proxy-signal/index.js.map +2 -2
- package/dist/proxy-signal/index.mjs +10 -10
- package/dist/proxy-signal/index.mjs.map +2 -2
- package/dist/request/index.js +16 -16
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.mjs +16 -16
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +21 -20
- package/dist/router/index.js.map +2 -2
- package/dist/router/index.mjs +21 -20
- package/dist/router/index.mjs.map +2 -2
- package/dist/signal/index.d.ts +7 -18
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +29 -48
- package/dist/signal/index.js.map +3 -3
- package/dist/signal/index.mjs +31 -50
- package/dist/signal/index.mjs.map +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/index.js.map +2 -2
- package/dist/store/index.mjs +2 -2
- package/dist/store/index.mjs.map +2 -2
- package/lib/dataset/index.ts +25 -25
- package/lib/hooks/index.ts +25 -54
- package/lib/index.ts +465 -715
- package/lib/node/index.ts +2 -2
- package/lib/node/utils/icons.ts +5 -5
- package/lib/node/utils/inline.ts +17 -17
- package/lib/node/utils/sw.ts +3 -3
- package/lib/node/utils/tree-adapter.ts +81 -52
- package/lib/proxy-signal/index.ts +10 -10
- package/lib/request/index.ts +16 -16
- package/lib/router/index.ts +21 -20
- package/lib/signal/index.ts +56 -131
- package/lib/store/index.ts +2 -2
- package/package.json +10 -3
- package/lib/index.d.ts +0 -0
- package/lib/interfaces.ts.bak +0 -141
package/lib/request/index.ts
CHANGED
|
@@ -54,7 +54,7 @@ export interface RequestInterface {
|
|
|
54
54
|
function serialize(obj: Record<string, any>, prefix: string = ""): string {
|
|
55
55
|
return Object.keys(obj)
|
|
56
56
|
.map((prop: string) => {
|
|
57
|
-
|
|
57
|
+
const k = prefix ? `${prefix}[${prop}]` : prop;
|
|
58
58
|
return typeof obj[prop] === "object"
|
|
59
59
|
? serialize(obj[prop], k)
|
|
60
60
|
: `${encodeURIComponent(k)}=${encodeURIComponent(obj[prop])}`;
|
|
@@ -65,7 +65,7 @@ function serialize(obj: Record<string, any>, prefix: string = ""): string {
|
|
|
65
65
|
function parseUrl(url: string, options: RequestOptionsWithUrls) {
|
|
66
66
|
let u = /^https?/gi.test(url) ? url : options.urls.base + url;
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
const parts = u.split("?");
|
|
69
69
|
u = parts[0].trim().replace(/^\/\//, "/").replace(/\/$/, "").trim();
|
|
70
70
|
|
|
71
71
|
if (parts[1]) {
|
|
@@ -92,7 +92,7 @@ const defaultOptions: RequestOptions = { allowedMethods: ["get", "post", "put",
|
|
|
92
92
|
|
|
93
93
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
94
94
|
function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
95
|
-
|
|
95
|
+
const url = baseUrl.replace(/\/$/gi, "").trim();
|
|
96
96
|
if (!options.urls) {
|
|
97
97
|
options.urls = {
|
|
98
98
|
base: "",
|
|
@@ -105,7 +105,7 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
105
105
|
options.allowedMethods = defaultOptions.allowedMethods;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
const opts: RequestOptionsWithUrls = {
|
|
109
109
|
...(options as RequestOptionsWithUrls),
|
|
110
110
|
urls: {
|
|
111
111
|
node: options.urls.node || null,
|
|
@@ -115,7 +115,7 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
115
115
|
};
|
|
116
116
|
|
|
117
117
|
const request = async function request(method: string, url: string, data?: Record<string, any>, options = {}) {
|
|
118
|
-
|
|
118
|
+
const innerOptions: SendOptions = {
|
|
119
119
|
method: method.toUpperCase(),
|
|
120
120
|
headers: {},
|
|
121
121
|
resolveWithFullResponse: false,
|
|
@@ -127,8 +127,8 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
127
127
|
innerOptions.headers.Accept = "application/json";
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
130
|
+
const acceptType = innerOptions.headers.Accept;
|
|
131
|
+
const contentType = innerOptions.headers["Content-Type"] || innerOptions.headers["content-type"] || "";
|
|
132
132
|
|
|
133
133
|
if (innerOptions.allowedMethods.indexOf(method) === -1) {
|
|
134
134
|
throw new Error("Method not allowed");
|
|
@@ -148,7 +148,7 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
148
148
|
formData = data;
|
|
149
149
|
} else {
|
|
150
150
|
formData = new FormData();
|
|
151
|
-
for (
|
|
151
|
+
for (const i in data) {
|
|
152
152
|
formData.append(i, data[i]);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -157,10 +157,10 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
|
|
160
|
+
const response = await fetch(parseUrl(url, opts), innerOptions);
|
|
161
161
|
let body = null;
|
|
162
162
|
if (!response.ok) {
|
|
163
|
-
|
|
163
|
+
const err = new Error(response.statusText) as Error & { response?: any; body?: any };
|
|
164
164
|
err.response = response;
|
|
165
165
|
if (/text/gi.test(acceptType)) {
|
|
166
166
|
err.body = await response.text();
|
|
@@ -203,15 +203,15 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
203
203
|
request.setOption = (key: string, value: any) => {
|
|
204
204
|
let result = opts;
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
const parsed = key.split(".");
|
|
207
207
|
let next;
|
|
208
208
|
|
|
209
209
|
while (parsed.length) {
|
|
210
210
|
next = parsed.shift() as string;
|
|
211
211
|
|
|
212
|
-
|
|
212
|
+
const nextIsArray = next.indexOf("[") > -1;
|
|
213
213
|
if (nextIsArray) {
|
|
214
|
-
|
|
214
|
+
const idx = next.replace(/\D/gi, "");
|
|
215
215
|
next = next.split("[")[0];
|
|
216
216
|
parsed.unshift(idx);
|
|
217
217
|
}
|
|
@@ -236,15 +236,15 @@ function Requester(baseUrl = "", options: RequestOptions = defaultOptions) {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
let result = opts;
|
|
239
|
-
|
|
239
|
+
const parsed = key.split(".");
|
|
240
240
|
let next;
|
|
241
241
|
|
|
242
242
|
while (parsed.length) {
|
|
243
243
|
next = parsed.shift() as string;
|
|
244
244
|
|
|
245
|
-
|
|
245
|
+
const nextIsArray = next.indexOf("[") > -1;
|
|
246
246
|
if (nextIsArray) {
|
|
247
|
-
|
|
247
|
+
const idx = next.replace(/\D/gi, "");
|
|
248
248
|
next = next.split("[")[0];
|
|
249
249
|
parsed.unshift(idx);
|
|
250
250
|
}
|
package/lib/router/index.ts
CHANGED
|
@@ -104,15 +104,15 @@ const addPath = ({
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// Trim trailing slashes from the path
|
|
107
|
-
|
|
107
|
+
const realpath = path.replace(/(\S)(\/+)$/, "$1");
|
|
108
108
|
|
|
109
109
|
// Find the express-like params in the path
|
|
110
|
-
|
|
110
|
+
const params = (realpath.match(/:(\w+)?/gi) || [])
|
|
111
111
|
// Set the names of the params found
|
|
112
112
|
.map((param) => param.slice(1));
|
|
113
113
|
|
|
114
114
|
// Generate a regular expression to match the path
|
|
115
|
-
|
|
115
|
+
const regexpPath = "^" + realpath.replace(/:(\w+)/gi, "([^\\/\\s]+)") + "$";
|
|
116
116
|
|
|
117
117
|
router.paths.push({
|
|
118
118
|
method,
|
|
@@ -126,12 +126,12 @@ const addPath = ({
|
|
|
126
126
|
// Parse a query string into an object
|
|
127
127
|
function parseQuery(queryParts?: string): Record<string, string> {
|
|
128
128
|
// Split the query string into an array of name-value pairs
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
const parts = queryParts ? queryParts.split("&") : [];
|
|
130
|
+
const query: Record<string, string> = {};
|
|
131
131
|
|
|
132
132
|
// Iterate over the name-value pairs and add them to the query object
|
|
133
|
-
for (
|
|
134
|
-
|
|
133
|
+
for (const nameValue of parts) {
|
|
134
|
+
const [name, value] = nameValue.split("=", 2);
|
|
135
135
|
query[name] = value || "";
|
|
136
136
|
}
|
|
137
137
|
|
|
@@ -140,13 +140,13 @@ function parseQuery(queryParts?: string): Record<string, string> {
|
|
|
140
140
|
|
|
141
141
|
// Search for middlewares that match a given path
|
|
142
142
|
function searchMiddlewares(router: RouterInterface, path: string): Middlewares {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
143
|
+
const middlewares: Middlewares = [];
|
|
144
|
+
const params: Record<string, any> = {};
|
|
145
|
+
const matches = [];
|
|
146
146
|
|
|
147
147
|
// Search for middlewares
|
|
148
|
-
for (
|
|
149
|
-
|
|
148
|
+
for (const item of router.paths) {
|
|
149
|
+
const match = item.regexp.exec(path);
|
|
150
150
|
|
|
151
151
|
// If we found middlewares
|
|
152
152
|
if (Array.isArray(match)) {
|
|
@@ -154,7 +154,7 @@ function searchMiddlewares(router: RouterInterface, path: string): Middlewares {
|
|
|
154
154
|
match.shift();
|
|
155
155
|
|
|
156
156
|
// Parse params
|
|
157
|
-
for (
|
|
157
|
+
for (const [index, key] of item.params.entries()) {
|
|
158
158
|
params[key] = match[index];
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -228,13 +228,13 @@ export class Router implements RouterInterface {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
add(path: string, ...middlewares: Middlewares): Router {
|
|
231
|
-
|
|
231
|
+
const pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
232
232
|
addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
|
|
233
233
|
return this;
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
use(...middlewares: Middlewares | Router[] | string[]): Router {
|
|
237
|
-
|
|
237
|
+
const path = getPathWithoutLastSlash(
|
|
238
238
|
`${this.pathPrefix}${typeof middlewares[0] === "string" ? middlewares.shift() : "/"}`
|
|
239
239
|
);
|
|
240
240
|
|
|
@@ -273,7 +273,7 @@ export class Router implements RouterInterface {
|
|
|
273
273
|
throw new Error("router.url.required");
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
|
|
276
|
+
const constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
277
277
|
const parts = constructedPath.split("?", 2);
|
|
278
278
|
this.url = constructedPath;
|
|
279
279
|
this.query = parseQuery(parts[1]);
|
|
@@ -337,15 +337,16 @@ export function mountRouter(elementContainer: string | any, router: Router): voi
|
|
|
337
337
|
|
|
338
338
|
if (!isNodeJs) {
|
|
339
339
|
function onPopStateGoToRoute(): void {
|
|
340
|
-
|
|
340
|
+
const pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
|
|
341
341
|
(router as unknown as Router).go(pathWithoutPrefix, undefined, true);
|
|
342
342
|
}
|
|
343
343
|
window.addEventListener("popstate", onPopStateGoToRoute, false);
|
|
344
344
|
onPopStateGoToRoute();
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
-
directive("route", (
|
|
348
|
-
|
|
349
|
-
setAttribute("
|
|
347
|
+
directive("route", (vnode: VnodeWithDom): void => {
|
|
348
|
+
const url = vnode.props["v-route"];
|
|
349
|
+
setAttribute("href", url, vnode);
|
|
350
|
+
setAttribute("onclick", router.getOnClickHandler(url), vnode);
|
|
350
351
|
});
|
|
351
352
|
}
|
package/lib/signal/index.ts
CHANGED
|
@@ -1,161 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
25
|
-
export function Signal(initialValue: any): SignalInterface {
|
|
26
|
-
// Create a copy of the current context object
|
|
27
|
-
const { vnode, component } = { ...current };
|
|
28
|
-
|
|
29
|
-
// Check if the context object has a vnode property
|
|
30
|
-
if (vnode && component) {
|
|
31
|
-
// Is first call
|
|
32
|
-
if (!vnode.components) {
|
|
33
|
-
// Set the components property to an empty array
|
|
34
|
-
vnode.components = [];
|
|
1
|
+
import { updateVnode, current, VnodeWithDom, onCleanup, POJOComponent, Component, onUnmount } from "valyrian.js";
|
|
2
|
+
|
|
3
|
+
type getter = () => any;
|
|
4
|
+
type setter = (newValue: any) => void;
|
|
5
|
+
type unsubscribe = () => void;
|
|
6
|
+
type subscribe = (callback: () => void) => unsubscribe;
|
|
7
|
+
type subscriptions = Set<() => void>;
|
|
8
|
+
type signal = [getter, setter, subscribe, subscriptions];
|
|
9
|
+
|
|
10
|
+
type SignalCalls = {
|
|
11
|
+
signals: signal[];
|
|
12
|
+
signal_calls: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const componentToSignalsWeakMap = new WeakMap<Component | POJOComponent, SignalCalls>();
|
|
16
|
+
|
|
17
|
+
// Signal is a generic function that creates a reactive state with a getter, setter, and subscribe mechanism.
|
|
18
|
+
export function Signal<T>(initialValue: T): signal {
|
|
19
|
+
if (current.component) {
|
|
20
|
+
if (componentToSignalsWeakMap.has(current.component) === false) {
|
|
21
|
+
const SignalCalls = { signals: [], signal_calls: -1 };
|
|
22
|
+
componentToSignalsWeakMap.set(current.component, SignalCalls);
|
|
23
|
+
onUnmount(() => componentToSignalsWeakMap.delete(current.component as Component | POJOComponent));
|
|
35
24
|
}
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Set the calls property to -1
|
|
40
|
-
vnode.signal_calls = -1;
|
|
41
|
-
// Add the component to the components array
|
|
42
|
-
vnode.components.push(component);
|
|
43
|
-
|
|
44
|
-
// Check if the component object has a signals property
|
|
45
|
-
if (!component.signals) {
|
|
46
|
-
// Set the signals property of the component object to an empty array
|
|
47
|
-
component.signals = [];
|
|
48
|
-
// Add a function to the cleanup stack that removes the signals property from the component object
|
|
49
|
-
onUnmount(() => Reflect.deleteProperty(component, "signals"));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
26
|
+
const SignalCalls = componentToSignalsWeakMap.get(current.component) as SignalCalls;
|
|
27
|
+
onCleanup(() => (SignalCalls.signal_calls = -1));
|
|
52
28
|
|
|
53
|
-
|
|
54
|
-
let signal: SignalInterface = component.signals[++vnode.signal_calls];
|
|
29
|
+
const signal = SignalCalls.signals[++SignalCalls.signal_calls];
|
|
55
30
|
|
|
56
|
-
// If a signal has already been assigned to the signal variable, return it
|
|
57
31
|
if (signal) {
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return signal;
|
|
32
|
+
// Return the signal if it already exists.
|
|
33
|
+
// But without the subscribe function. This is to prevent the subscribe function from being called multiple times.
|
|
34
|
+
const fakeSubscribe = (() => {}) as unknown as subscribe;
|
|
35
|
+
return [signal[0], signal[1], fakeSubscribe, signal[3]];
|
|
63
36
|
}
|
|
64
37
|
}
|
|
65
38
|
|
|
66
|
-
//
|
|
67
|
-
let value = initialValue;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const subscriptions: SubscriptionsInterface = [];
|
|
39
|
+
// The current value of the signal is stored in a closure to maintain state.
|
|
40
|
+
let value: T = initialValue;
|
|
41
|
+
// Subscribers is a Set of functions to be called whenever the value changes.
|
|
42
|
+
const subscribers: subscriptions = new Set();
|
|
71
43
|
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
44
|
+
// subscribe is a function that allows a subscriber to listen to changes in the signal's value.
|
|
45
|
+
// It returns an unsubscribe function to stop listening to changes.
|
|
46
|
+
const subscribe = (callback: () => void) => {
|
|
47
|
+
subscribers.add(callback);
|
|
48
|
+
return () => subscribers.delete(callback);
|
|
78
49
|
};
|
|
79
50
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// This is the function that will be called when the Signal's value changes
|
|
84
|
-
const updateVnodes = () => {
|
|
85
|
-
// Create a copy of the vnodesToUpdate array and filter out any duplicate vnodes
|
|
86
|
-
let vnodesToUpdateCopy = vnodesToUpdate.filter((vnode, index, self) => {
|
|
87
|
-
return self.findIndex((v) => v.dom === vnode.dom) === index;
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Loop through the vnodesToUpdate array
|
|
91
|
-
for (let i = 0, l = vnodesToUpdateCopy.length; i < l; i++) {
|
|
92
|
-
const vnode2 = vnodesToUpdateCopy[i];
|
|
93
|
-
// If it does, create a new vnode object based on the original vnode, its children, and its DOM and SVG properties
|
|
94
|
-
let newVnode = v(vnode2.tag, vnode2.props, ...vnode2.initialChildren) as VnodeWithDom;
|
|
95
|
-
newVnode.dom = vnode2.dom; // Set the new vnode object's DOM property to the old vnode object's DOM property
|
|
96
|
-
newVnode.isSVG = vnode2.isSVG; // Set the new vnode object's isSVG property to the old vnode object's isSVG property
|
|
97
|
-
|
|
98
|
-
// Update the vnode object
|
|
99
|
-
updateVnode(newVnode, vnode2);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
51
|
+
const domToVnodesToUpdate: Map<Node, VnodeWithDom> = new Map();
|
|
52
|
+
const updateVnodes = () => domToVnodesToUpdate.forEach((vnode) => updateVnode(vnode));
|
|
102
53
|
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// If we have a current vnode, it means that a get function is being called from within a component
|
|
109
|
-
// so we subscribe the vnode to be updated when the Signal's value changes
|
|
110
|
-
if (vnode2 && vnodesToUpdate.indexOf(vnode2) === -1) {
|
|
111
|
-
// We set the initialChildren to a copy of the vnode's children array
|
|
112
|
-
// This is the case when the vnode is a component that has not been rendered yet and we need the initial children
|
|
113
|
-
// because they could have the components that are using the Signal
|
|
114
|
-
if (!vnode2.initialChildren) {
|
|
115
|
-
vnode2.initialChildren = [...vnode2.children];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Add the vnode to the vnodesToUpdate array
|
|
119
|
-
vnodesToUpdate.push(vnode2);
|
|
120
|
-
|
|
121
|
-
// Subscribe the updateVnodes function to the Signal
|
|
54
|
+
// getValue is a function that returns the current value of the signal.
|
|
55
|
+
const getValue = () => {
|
|
56
|
+
if (current.vnode) {
|
|
57
|
+
const vnode = current.vnode as VnodeWithDom;
|
|
58
|
+
domToVnodesToUpdate.set(vnode.dom, vnode);
|
|
122
59
|
subscribe(updateVnodes);
|
|
123
60
|
}
|
|
124
|
-
|
|
125
|
-
// Return the current value of the Signal
|
|
126
61
|
return value;
|
|
127
|
-
}
|
|
62
|
+
};
|
|
128
63
|
|
|
129
|
-
//
|
|
130
|
-
const
|
|
131
|
-
// If we have a current event on going, prevent the default action
|
|
64
|
+
// setValue is a function that updates the value of the signal and notifies subscribers.
|
|
65
|
+
const setValue = (newValue: any) => {
|
|
132
66
|
if (current.event) {
|
|
133
67
|
current.event.preventDefault();
|
|
134
68
|
}
|
|
135
69
|
|
|
136
|
-
|
|
137
|
-
if (newValue === value) {
|
|
70
|
+
if (value === newValue) {
|
|
138
71
|
return;
|
|
139
72
|
}
|
|
140
|
-
|
|
141
|
-
// Update the value of the Signal
|
|
142
73
|
value = newValue;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
for (let i = 0, l = subscriptions.length; i < l; i++) {
|
|
146
|
-
subscriptions[i](value);
|
|
147
|
-
}
|
|
74
|
+
// Notify all subscribers by invoking their callback functions.
|
|
75
|
+
subscribers.forEach((subscriber) => subscriber());
|
|
148
76
|
};
|
|
149
77
|
|
|
150
|
-
|
|
151
|
-
let signal: SignalInterface = [get, set, subscribe, subscriptions];
|
|
78
|
+
const signal: signal = [getValue, setValue, subscribe, subscribers];
|
|
152
79
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
component.signals.push(signal);
|
|
80
|
+
if (current.component) {
|
|
81
|
+
const SignalCalls = componentToSignalsWeakMap.get(current.component) as SignalCalls;
|
|
82
|
+
SignalCalls.signals.push(signal);
|
|
157
83
|
}
|
|
158
84
|
|
|
159
|
-
// Return the signal
|
|
160
85
|
return signal;
|
|
161
86
|
}
|
package/lib/store/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ function deepFreeze(obj: any) {
|
|
|
31
31
|
deepFreeze(obj[i]);
|
|
32
32
|
}
|
|
33
33
|
} else {
|
|
34
|
-
|
|
34
|
+
const props = Reflect.ownKeys(obj);
|
|
35
35
|
for (let i = 0, l = props.length; i < l; i++) {
|
|
36
36
|
deepFreeze(obj[props[i]]);
|
|
37
37
|
}
|
|
@@ -60,7 +60,7 @@ export const Store = function Store(
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
const localState = typeof state === "function" ? state() : state;
|
|
64
64
|
|
|
65
65
|
this.state = new Proxy(localState || {}, {
|
|
66
66
|
get: (state, prop: string) => deepFreeze(state[prop]),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valyrian.js",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.12",
|
|
4
4
|
"description": "Lightweight steel to forge PWAs. (Minimal Frontend Framework with server side rendering and other capabilities)",
|
|
5
5
|
"repository": "git@github.com:Masquerade-Circus/valyrian.js.git",
|
|
6
6
|
"author": "Masquerade <christian@masquerade-circus.net>",
|
|
@@ -20,8 +20,15 @@
|
|
|
20
20
|
"import": "./dist/index.mjs",
|
|
21
21
|
"require": "./dist/index.js"
|
|
22
22
|
},
|
|
23
|
+
"./lib": {
|
|
24
|
+
"types": "./lib/index.ts",
|
|
25
|
+
"import": "./lib/index.ts",
|
|
26
|
+
"require": "./lib/index.ts"
|
|
27
|
+
},
|
|
23
28
|
"./lib/*": {
|
|
24
|
-
"
|
|
29
|
+
"types": "./lib/*/index.ts",
|
|
30
|
+
"import": "./lib/*/index.ts",
|
|
31
|
+
"require": "./lib/*/index.ts"
|
|
25
32
|
},
|
|
26
33
|
"./*": {
|
|
27
34
|
"types": "./dist/*.d.ts",
|
|
@@ -60,7 +67,7 @@
|
|
|
60
67
|
},
|
|
61
68
|
"scripts": {
|
|
62
69
|
"dev:source": "NODE_ENV=development nodemon --enable-source-maps -e tsx,ts,json,css -w ./lib -w ./www source.js",
|
|
63
|
-
"dev:test": "nodemon --enable-source-maps -e mjs,js,ts,json,css,tsx,jsx -w ./lib -w ./test -w ./dist --exec 'mocha --bail --timeout 15000 --slow 0 --require ./register --enable-source-maps \"test/**/*_test.js\"'",
|
|
70
|
+
"dev:test": "nodemon --enable-source-maps -e mjs,js,ts,json,css,tsx,jsx -w ./lib -w ./test -w ./dist --exec 'mocha --bail --timeout 15000 --slow 0 --require ./register --enable-source-maps --reporter ./test/reporter.js \"test/**/*_test.js\"'",
|
|
64
71
|
"dev:test:nyc": "nodemon --enable-source-maps -w ./test -w ./lib -w ./plugins --exec 'nyc --reporter=text --reporter=lcov mocha --timeout 15000 --slow 0 --require ./register \"test/**/*_test.js\"'",
|
|
65
72
|
"dev:web": "browser-sync start --config 'www/bs-config.js'",
|
|
66
73
|
"build": "npm run build:source && npm run remark",
|
package/lib/index.d.ts
DELETED
|
File without changes
|
package/lib/interfaces.ts.bak
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
/* eslint-disable no-unused-vars */
|
|
3
|
-
declare module "valyrian.js" {
|
|
4
|
-
interface DefaultRecord extends Record<string | number | symbol, any> {}
|
|
5
|
-
|
|
6
|
-
// The VnodeProperties interface represents properties that can be passed to a virtual node.
|
|
7
|
-
export interface VnodeProperties extends DefaultRecord {
|
|
8
|
-
// A unique key for the virtual node, which can be a string or a number.
|
|
9
|
-
// This is useful for optimizing updates in a list of nodes.
|
|
10
|
-
key?: string | number;
|
|
11
|
-
// A state object that is associated with the virtual node.
|
|
12
|
-
state?: any;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// The DomElement interface extends the Element interface with an index signature.
|
|
16
|
-
// This allows for any additional properties to be added to DOM elements.
|
|
17
|
-
export interface DomElement extends Element, DefaultRecord {}
|
|
18
|
-
|
|
19
|
-
// The VnodeInterface represents a virtual node. It has a number of optional fields,
|
|
20
|
-
// including a tag, props, children, and a DOM element.
|
|
21
|
-
export interface VnodeInterface extends DefaultRecord {
|
|
22
|
-
// The constructor for the virtual node. It takes a tag, props, and children as arguments.
|
|
23
|
-
// The tag can be a string, a component, or a POJO component.
|
|
24
|
-
// eslint-disable-next-line no-unused-vars
|
|
25
|
-
new (tag: string | Component | POJOComponent, props: VnodeProperties, children: Children): VnodeInterface;
|
|
26
|
-
// The tag for the virtual node. It can be a string, a component, or a POJO component.
|
|
27
|
-
tag: string | Component | POJOComponent;
|
|
28
|
-
// The props for the virtual node.
|
|
29
|
-
props: VnodeProperties;
|
|
30
|
-
// The children for the virtual node.
|
|
31
|
-
children: Children;
|
|
32
|
-
// A boolean indicating whether the virtual node is an SVG element.
|
|
33
|
-
isSVG?: boolean;
|
|
34
|
-
// The DOM element that corresponds to the virtual node.
|
|
35
|
-
dom?: DomElement;
|
|
36
|
-
// A boolean indicating whether the virtual node has been processed in the keyed diffing algorithm.
|
|
37
|
-
processed?: boolean;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// The VnodeWithDom interface represents a virtual node that has a DOM element associated with it.
|
|
41
|
-
export interface VnodeWithDom extends VnodeInterface {
|
|
42
|
-
dom: DomElement;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// The Component interface represents a function that returns a virtual node or a list of virtual nodes.
|
|
46
|
-
// It can also have additional properties.
|
|
47
|
-
export interface Component extends DefaultRecord {
|
|
48
|
-
// The function that returns a virtual node or a list of virtual nodes.
|
|
49
|
-
// It can take props and children as arguments.
|
|
50
|
-
// eslint-disable-next-line no-unused-vars
|
|
51
|
-
(props?: VnodeProperties | null, ...children: any[]): VnodeInterface | Children | any;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// The POJOComponent interface represents a "plain old JavaScript object" (POJO) component.
|
|
55
|
-
// It has a view function that returns a virtual node or a list of virtual nodes,
|
|
56
|
-
// as well as optional props and children.
|
|
57
|
-
// It can be used also to identify class instance components.
|
|
58
|
-
export interface POJOComponent extends DefaultRecord {
|
|
59
|
-
// The view function that returns a virtual node or a list of virtual nodes.
|
|
60
|
-
view: Component;
|
|
61
|
-
// The props for the component.
|
|
62
|
-
props?: VnodeProperties | null;
|
|
63
|
-
// The children for the component.
|
|
64
|
-
children?: any[];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// The VnodeComponentInterface represents a virtual node that has a component as its tag.
|
|
68
|
-
// It has props and children, just like a regular virtual node.
|
|
69
|
-
export interface VnodeComponentInterface extends VnodeInterface {
|
|
70
|
-
tag: Component | POJOComponent;
|
|
71
|
-
props: VnodeProperties;
|
|
72
|
-
children: Children;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// The Children interface represents a list of virtual nodes or other values.
|
|
76
|
-
export interface Children extends Array<VnodeInterface | VnodeComponentInterface | any> {}
|
|
77
|
-
|
|
78
|
-
// The Directive interface represents a function that can be applied to a virtual node.
|
|
79
|
-
// It receives the value, virtual node, and old virtual node as arguments, and can return a boolean value.
|
|
80
|
-
// If only the virtual node is passed, it means its the on create phase for the v-node.
|
|
81
|
-
// If the old virtual node is also passed, it means its the on update phase for the v-node.
|
|
82
|
-
export interface Directive {
|
|
83
|
-
// eslint-disable-next-line no-unused-vars
|
|
84
|
-
(value: any, vnode: VnodeWithDom, oldVnode?: VnodeWithDom): void | boolean;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// The Directives interface is a mapping of directive names to Directive functions.
|
|
88
|
-
export interface Directives extends Record<string, Directive> {}
|
|
89
|
-
|
|
90
|
-
// The ReservedProps interface is a mapping of reserved prop names to the value `true`.
|
|
91
|
-
// These prop names cannot be used as custom prop names.
|
|
92
|
-
export interface ReservedProps extends Record<string, true> {}
|
|
93
|
-
|
|
94
|
-
// The Current interface represents the current component and virtual node that are being processed.
|
|
95
|
-
export interface Current {
|
|
96
|
-
// The current component. It can be a component, a POJO component, or null.
|
|
97
|
-
component: Component | POJOComponent | null;
|
|
98
|
-
// The current virtual node. It must have a DOM element associated with it.
|
|
99
|
-
vnode: VnodeWithDom | null;
|
|
100
|
-
// The old virtual node. It must have a DOM element associated with it.
|
|
101
|
-
oldVnode?: VnodeWithDom | null;
|
|
102
|
-
// The current event. It can be an event or null.
|
|
103
|
-
event: Event | null;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// The V function is the main function for creating virtual nodes.
|
|
107
|
-
// It takes a tag or component, props, and children as arguments, and returns a virtual node.
|
|
108
|
-
export interface V {
|
|
109
|
-
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
110
|
-
(tagOrComponent: string | Component | POJOComponent, props: VnodeProperties | null, ...children: Children):
|
|
111
|
-
| VnodeInterface
|
|
112
|
-
| VnodeComponentInterface;
|
|
113
|
-
// eslint-disable-next-line no-unused-vars, no-use-before-define
|
|
114
|
-
fragment(_: any, ...children: Children): Children;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export let isNodeJs: boolean;
|
|
118
|
-
export function createDomElement(tag: string, isSVG?: boolean): DomElement;
|
|
119
|
-
export const Vnode: VnodeInterface;
|
|
120
|
-
export function isComponent(component: any): component is Component;
|
|
121
|
-
export const isVnode: (object?: unknown | VnodeInterface) => object is VnodeInterface;
|
|
122
|
-
export const isVnodeComponent: (object?: unknown | VnodeComponentInterface) => object is VnodeComponentInterface;
|
|
123
|
-
export function domToVnode(dom: any): VnodeWithDom;
|
|
124
|
-
export function trust(htmlString: string): any;
|
|
125
|
-
export const current: Current;
|
|
126
|
-
export const reservedProps: Record<string, true>;
|
|
127
|
-
export function onMount(callback: any): void;
|
|
128
|
-
export function onUpdate(callback: any): void;
|
|
129
|
-
export function onCleanup(callback: any): void;
|
|
130
|
-
export function onUnmount(callback: any): void;
|
|
131
|
-
export const directives: Directives;
|
|
132
|
-
export function directive(name: string, directive: Directive): void;
|
|
133
|
-
export function setAttribute(name: string, value: any, newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
134
|
-
export function updateAttributes(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
135
|
-
export function patch(newVnode: VnodeWithDom, oldVnode?: VnodeWithDom): void;
|
|
136
|
-
export function update(): void | string;
|
|
137
|
-
export function updateVnode(vnode: VnodeWithDom, oldVnode: VnodeWithDom): string | void;
|
|
138
|
-
export function unmount(): string | void;
|
|
139
|
-
export function mount(dom: any, component: any): string | void;
|
|
140
|
-
export const v: V;
|
|
141
|
-
}
|