rask-ui 0.2.4 → 0.2.6
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/vdom/AbstractVNode.d.ts +24 -2
- package/dist/vdom/AbstractVNode.d.ts.map +1 -1
- package/dist/vdom/AbstractVNode.js +153 -13
- package/dist/vdom/ComponentVNode.d.ts +2 -2
- package/dist/vdom/ComponentVNode.d.ts.map +1 -1
- package/dist/vdom/ComponentVNode.js +11 -13
- package/dist/vdom/ElementVNode.d.ts +2 -8
- package/dist/vdom/ElementVNode.d.ts.map +1 -1
- package/dist/vdom/ElementVNode.js +15 -32
- package/dist/vdom/FragmentVNode.d.ts +2 -2
- package/dist/vdom/FragmentVNode.d.ts.map +1 -1
- package/dist/vdom/FragmentVNode.js +12 -3
- package/dist/vdom/RootVNode.d.ts +2 -2
- package/dist/vdom/RootVNode.d.ts.map +1 -1
- package/dist/vdom/RootVNode.js +7 -5
- package/package.json +1 -1
- package/dist/component.d.ts +0 -38
- package/dist/component.d.ts.map +0 -1
- package/dist/component.js +0 -130
- package/dist/context.d.ts +0 -5
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -29
- package/dist/createAsync.test.d.ts +0 -2
- package/dist/createAsync.test.d.ts.map +0 -1
- package/dist/createAsync.test.js +0 -110
- package/dist/createAsyncState.d.ts +0 -16
- package/dist/createAsyncState.d.ts.map +0 -1
- package/dist/createAsyncState.js +0 -24
- package/dist/createContext.test.d.ts +0 -2
- package/dist/createContext.test.d.ts.map +0 -1
- package/dist/createContext.test.js +0 -136
- package/dist/createMutation.test.d.ts +0 -2
- package/dist/createMutation.test.d.ts.map +0 -1
- package/dist/createMutation.test.js +0 -168
- package/dist/createQuery.test.d.ts +0 -2
- package/dist/createQuery.test.d.ts.map +0 -1
- package/dist/createQuery.test.js +0 -156
- package/dist/createRef.test.d.ts +0 -2
- package/dist/createRef.test.d.ts.map +0 -1
- package/dist/createRef.test.js +0 -80
- package/dist/createState.test.d.ts +0 -2
- package/dist/createState.test.d.ts.map +0 -1
- package/dist/createState.test.js +0 -111
- package/dist/createView.test.d.ts +0 -2
- package/dist/createView.test.d.ts.map +0 -1
- package/dist/createView.test.js +0 -203
- package/dist/error.test.d.ts +0 -2
- package/dist/error.test.d.ts.map +0 -1
- package/dist/error.test.js +0 -144
- package/dist/integration.test.d.ts +0 -2
- package/dist/integration.test.d.ts.map +0 -1
- package/dist/integration.test.js +0 -155
- package/dist/jsx.d.ts.map +0 -1
- package/dist/jsx.js +0 -42
- package/dist/observation.test.d.ts +0 -2
- package/dist/observation.test.d.ts.map +0 -1
- package/dist/observation.test.js +0 -113
- package/dist/render-test.d.ts +0 -2
- package/dist/render-test.d.ts.map +0 -1
- package/dist/render-test.js +0 -21
- package/dist/render.d.ts +0 -7
- package/dist/render.d.ts.map +0 -1
- package/dist/render.js +0 -77
- package/dist/suspense.d.ts +0 -25
- package/dist/suspense.d.ts.map +0 -1
- package/dist/suspense.js +0 -97
- package/dist/tests/class.test.d.ts +0 -2
- package/dist/tests/class.test.d.ts.map +0 -1
- package/dist/tests/class.test.js +0 -185
- package/dist/tests/complex-rendering.test.d.ts +0 -2
- package/dist/tests/complex-rendering.test.d.ts.map +0 -1
- package/dist/tests/complex-rendering.test.js +0 -400
- package/dist/tests/component.cleanup.test.d.ts +0 -2
- package/dist/tests/component.cleanup.test.d.ts.map +0 -1
- package/dist/tests/component.cleanup.test.js +0 -325
- package/dist/tests/component.counter.test.d.ts +0 -2
- package/dist/tests/component.counter.test.d.ts.map +0 -1
- package/dist/tests/component.counter.test.js +0 -124
- package/dist/tests/component.interaction.test.d.ts +0 -2
- package/dist/tests/component.interaction.test.d.ts.map +0 -1
- package/dist/tests/component.interaction.test.js +0 -73
- package/dist/tests/component.props.test.d.ts +0 -2
- package/dist/tests/component.props.test.d.ts.map +0 -1
- package/dist/tests/component.props.test.js +0 -334
- package/dist/tests/component.return-types.test.d.ts +0 -2
- package/dist/tests/component.return-types.test.d.ts.map +0 -1
- package/dist/tests/component.return-types.test.js +0 -357
- package/dist/tests/component.state.test.d.ts +0 -2
- package/dist/tests/component.state.test.d.ts.map +0 -1
- package/dist/tests/component.state.test.js +0 -135
- package/dist/tests/component.test.d.ts +0 -2
- package/dist/tests/component.test.d.ts.map +0 -1
- package/dist/tests/component.test.js +0 -63
- package/dist/tests/createAsync.test.d.ts +0 -2
- package/dist/tests/createAsync.test.d.ts.map +0 -1
- package/dist/tests/createAsync.test.js +0 -110
- package/dist/tests/createContext.test.d.ts +0 -2
- package/dist/tests/createContext.test.d.ts.map +0 -1
- package/dist/tests/createContext.test.js +0 -141
- package/dist/tests/createMutation.test.d.ts +0 -2
- package/dist/tests/createMutation.test.d.ts.map +0 -1
- package/dist/tests/createMutation.test.js +0 -168
- package/dist/tests/createQuery.test.d.ts +0 -2
- package/dist/tests/createQuery.test.d.ts.map +0 -1
- package/dist/tests/createQuery.test.js +0 -156
- package/dist/tests/createRef.test.d.ts +0 -2
- package/dist/tests/createRef.test.d.ts.map +0 -1
- package/dist/tests/createRef.test.js +0 -84
- package/dist/tests/createState.test.d.ts +0 -2
- package/dist/tests/createState.test.d.ts.map +0 -1
- package/dist/tests/createState.test.js +0 -103
- package/dist/tests/createView.test.d.ts +0 -2
- package/dist/tests/createView.test.d.ts.map +0 -1
- package/dist/tests/createView.test.js +0 -203
- package/dist/tests/edge-cases.test.d.ts +0 -2
- package/dist/tests/edge-cases.test.d.ts.map +0 -1
- package/dist/tests/edge-cases.test.js +0 -637
- package/dist/tests/error-no-boundary.test.d.ts +0 -2
- package/dist/tests/error-no-boundary.test.d.ts.map +0 -1
- package/dist/tests/error-no-boundary.test.js +0 -174
- package/dist/tests/error.test.d.ts +0 -2
- package/dist/tests/error.test.d.ts.map +0 -1
- package/dist/tests/error.test.js +0 -199
- package/dist/tests/fragment.test.d.ts +0 -2
- package/dist/tests/fragment.test.d.ts.map +0 -1
- package/dist/tests/fragment.test.js +0 -618
- package/dist/tests/integration.test.d.ts +0 -2
- package/dist/tests/integration.test.d.ts.map +0 -1
- package/dist/tests/integration.test.js +0 -192
- package/dist/tests/keys.test.d.ts +0 -2
- package/dist/tests/keys.test.d.ts.map +0 -1
- package/dist/tests/keys.test.js +0 -293
- package/dist/tests/mount.test.d.ts +0 -2
- package/dist/tests/mount.test.d.ts.map +0 -1
- package/dist/tests/mount.test.js +0 -91
- package/dist/tests/observation.test.d.ts +0 -2
- package/dist/tests/observation.test.d.ts.map +0 -1
- package/dist/tests/observation.test.js +0 -113
- package/dist/tests/patch.test.d.ts +0 -2
- package/dist/tests/patch.test.d.ts.map +0 -1
- package/dist/tests/patch.test.js +0 -498
- package/dist/tests/patchChildren.test.d.ts +0 -2
- package/dist/tests/patchChildren.test.d.ts.map +0 -1
- package/dist/tests/patchChildren.test.js +0 -387
- package/dist/tests/primitives.test.d.ts +0 -2
- package/dist/tests/primitives.test.d.ts.map +0 -1
- package/dist/tests/primitives.test.js +0 -132
- package/dist/vdom/class.test.d.ts +0 -2
- package/dist/vdom/class.test.d.ts.map +0 -1
- package/dist/vdom/class.test.js +0 -143
- package/dist/vdom/complex-rendering.test.d.ts +0 -2
- package/dist/vdom/complex-rendering.test.d.ts.map +0 -1
- package/dist/vdom/complex-rendering.test.js +0 -400
- package/dist/vdom/component.cleanup.test.d.ts +0 -2
- package/dist/vdom/component.cleanup.test.d.ts.map +0 -1
- package/dist/vdom/component.cleanup.test.js +0 -323
- package/dist/vdom/component.counter.test.d.ts +0 -2
- package/dist/vdom/component.counter.test.d.ts.map +0 -1
- package/dist/vdom/component.counter.test.js +0 -124
- package/dist/vdom/component.interaction.test.d.ts +0 -2
- package/dist/vdom/component.interaction.test.d.ts.map +0 -1
- package/dist/vdom/component.interaction.test.js +0 -73
- package/dist/vdom/component.props.test.d.ts +0 -2
- package/dist/vdom/component.props.test.d.ts.map +0 -1
- package/dist/vdom/component.props.test.js +0 -88
- package/dist/vdom/component.return-types.test.d.ts +0 -2
- package/dist/vdom/component.return-types.test.d.ts.map +0 -1
- package/dist/vdom/component.return-types.test.js +0 -357
- package/dist/vdom/component.state.test.d.ts +0 -2
- package/dist/vdom/component.state.test.d.ts.map +0 -1
- package/dist/vdom/component.state.test.js +0 -129
- package/dist/vdom/component.test.d.ts +0 -2
- package/dist/vdom/component.test.d.ts.map +0 -1
- package/dist/vdom/component.test.js +0 -63
- package/dist/vdom/edge-cases.test.d.ts +0 -2
- package/dist/vdom/edge-cases.test.d.ts.map +0 -1
- package/dist/vdom/edge-cases.test.js +0 -637
- package/dist/vdom/fragment.test.d.ts +0 -2
- package/dist/vdom/fragment.test.d.ts.map +0 -1
- package/dist/vdom/fragment.test.js +0 -618
- package/dist/vdom/keys.test.d.ts +0 -2
- package/dist/vdom/keys.test.d.ts.map +0 -1
- package/dist/vdom/keys.test.js +0 -293
- package/dist/vdom/mount.test.d.ts +0 -2
- package/dist/vdom/mount.test.d.ts.map +0 -1
- package/dist/vdom/mount.test.js +0 -91
- package/dist/vdom/patch.test.d.ts +0 -2
- package/dist/vdom/patch.test.d.ts.map +0 -1
- package/dist/vdom/patch.test.js +0 -498
- package/dist/vdom/patchChildren.test.d.ts +0 -2
- package/dist/vdom/patchChildren.test.d.ts.map +0 -1
- package/dist/vdom/patchChildren.test.js +0 -392
- package/dist/vdom/primitives.test.d.ts +0 -2
- package/dist/vdom/primitives.test.d.ts.map +0 -1
- package/dist/vdom/primitives.test.js +0 -132
package/dist/component.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { thunk } from "snabbdom";
|
|
2
|
-
import { getCurrentObserver, Observer, Signal } from "./observation";
|
|
3
|
-
import { jsx, patch } from "./render";
|
|
4
|
-
import { createState } from "./createState";
|
|
5
|
-
const componentStack = [];
|
|
6
|
-
export function getCurrentComponent() {
|
|
7
|
-
return componentStack[0] || null;
|
|
8
|
-
}
|
|
9
|
-
export function onMount(cb) {
|
|
10
|
-
const current = componentStack[0];
|
|
11
|
-
if (!current) {
|
|
12
|
-
throw new Error("Only use onMount in component setup");
|
|
13
|
-
}
|
|
14
|
-
current.onMounts.push(cb);
|
|
15
|
-
}
|
|
16
|
-
export function onCleanup(cb) {
|
|
17
|
-
const current = componentStack[0];
|
|
18
|
-
if (!current) {
|
|
19
|
-
throw new Error("Only use onCleanup in component setup");
|
|
20
|
-
}
|
|
21
|
-
current.onCleanups.push(cb);
|
|
22
|
-
}
|
|
23
|
-
const hook = {
|
|
24
|
-
insert(vnode) {
|
|
25
|
-
componentStack.shift();
|
|
26
|
-
vnode.data.componentInstance.onMounts.forEach((cb) => cb());
|
|
27
|
-
},
|
|
28
|
-
destroy(vnode) {
|
|
29
|
-
vnode.data.componentInstance.onCleanups.forEach((cb) => cb());
|
|
30
|
-
},
|
|
31
|
-
prepatch(oldVnode, thunk) {
|
|
32
|
-
copyToThunk(oldVnode, thunk);
|
|
33
|
-
componentStack.unshift(thunk.data.componentInstance);
|
|
34
|
-
},
|
|
35
|
-
postpatch(_, newNode) {
|
|
36
|
-
const componentInstance = newNode.data.componentInstance;
|
|
37
|
-
componentStack.shift();
|
|
38
|
-
const props = newNode.data.args[0];
|
|
39
|
-
const children = newNode.data.args[1];
|
|
40
|
-
for (const key in props) {
|
|
41
|
-
componentInstance.reactiveProps[key] = props[key];
|
|
42
|
-
}
|
|
43
|
-
componentInstance.reactiveProps.children = children;
|
|
44
|
-
},
|
|
45
|
-
init(thunk) {
|
|
46
|
-
const component = thunk.data.fn;
|
|
47
|
-
const args = thunk.data.args;
|
|
48
|
-
let errorSignal;
|
|
49
|
-
let error;
|
|
50
|
-
const executeRender = () => {
|
|
51
|
-
const stopObserving = instance.observer.observe();
|
|
52
|
-
let renderResult = null;
|
|
53
|
-
try {
|
|
54
|
-
renderResult = render();
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
instance.notifyError(error);
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
stopObserving();
|
|
61
|
-
}
|
|
62
|
-
return jsx("component", {
|
|
63
|
-
hook: {
|
|
64
|
-
insert: hook.insert,
|
|
65
|
-
destroy: hook.destroy,
|
|
66
|
-
},
|
|
67
|
-
"data-name": component.name,
|
|
68
|
-
}, Array.isArray(renderResult) ? renderResult : [renderResult]);
|
|
69
|
-
};
|
|
70
|
-
const instance = {
|
|
71
|
-
parent: thunk.data.parentComponent || null,
|
|
72
|
-
component,
|
|
73
|
-
contexts: null,
|
|
74
|
-
onMounts: [],
|
|
75
|
-
onCleanups: [],
|
|
76
|
-
observer: new Observer(() => {
|
|
77
|
-
const renderResult = executeRender();
|
|
78
|
-
instance.hostNode = patch(instance.hostNode, renderResult);
|
|
79
|
-
}),
|
|
80
|
-
reactiveProps: createState({
|
|
81
|
-
...args[0],
|
|
82
|
-
children: args[1],
|
|
83
|
-
}),
|
|
84
|
-
get error() {
|
|
85
|
-
if (!errorSignal) {
|
|
86
|
-
errorSignal = new Signal();
|
|
87
|
-
}
|
|
88
|
-
const observer = getCurrentObserver();
|
|
89
|
-
if (observer) {
|
|
90
|
-
observer.subscribeSignal(errorSignal);
|
|
91
|
-
}
|
|
92
|
-
return error;
|
|
93
|
-
},
|
|
94
|
-
notifyError(childError) {
|
|
95
|
-
if (errorSignal) {
|
|
96
|
-
error = childError;
|
|
97
|
-
errorSignal.notify();
|
|
98
|
-
}
|
|
99
|
-
else if (instance.parent) {
|
|
100
|
-
instance.parent.notifyError(childError);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
throw childError;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
componentStack.unshift(instance);
|
|
108
|
-
const render = component(instance.reactiveProps);
|
|
109
|
-
const renderResult = executeRender();
|
|
110
|
-
renderResult.data.componentInstance = instance;
|
|
111
|
-
copyToThunk(renderResult, thunk);
|
|
112
|
-
instance.hostNode = thunk;
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
export function createComponent(component, props, children) {
|
|
116
|
-
const thunkNode = thunk("component", props.key, component, [props, children]);
|
|
117
|
-
Object.assign(thunkNode.data.hook, hook);
|
|
118
|
-
// Capture the parent component at vnode creation time (during render)
|
|
119
|
-
// rather than at init time, to ensure correct parent relationships
|
|
120
|
-
thunkNode.data.parentComponent = getCurrentComponent();
|
|
121
|
-
return thunkNode;
|
|
122
|
-
}
|
|
123
|
-
function copyToThunk(vnode, thunk) {
|
|
124
|
-
vnode.data.fn = thunk.data.fn;
|
|
125
|
-
vnode.data.args = thunk.data.args;
|
|
126
|
-
thunk.data = vnode.data;
|
|
127
|
-
thunk.children = vnode.children;
|
|
128
|
-
thunk.text = vnode.text;
|
|
129
|
-
thunk.elm = vnode.elm;
|
|
130
|
-
}
|
package/dist/context.d.ts
DELETED
package/dist/context.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM;eAE/B,CAAC;WAaL,CAAC;EAmBX"}
|
package/dist/context.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getCurrentComponent } from "./component";
|
|
2
|
-
export function createContext() {
|
|
3
|
-
const context = {
|
|
4
|
-
set(value) {
|
|
5
|
-
const currentComponent = getCurrentComponent();
|
|
6
|
-
if (!currentComponent) {
|
|
7
|
-
throw new Error("You can not set context out component setup");
|
|
8
|
-
}
|
|
9
|
-
if (!currentComponent.contexts) {
|
|
10
|
-
currentComponent.contexts = new Map();
|
|
11
|
-
}
|
|
12
|
-
currentComponent.contexts.set(context, value);
|
|
13
|
-
},
|
|
14
|
-
get() {
|
|
15
|
-
let currentComponent = getCurrentComponent();
|
|
16
|
-
if (!currentComponent) {
|
|
17
|
-
throw new Error("You can not set context out component setup");
|
|
18
|
-
}
|
|
19
|
-
while (currentComponent) {
|
|
20
|
-
if (currentComponent.contexts?.has(context)) {
|
|
21
|
-
return currentComponent.contexts.get(context);
|
|
22
|
-
}
|
|
23
|
-
currentComponent = currentComponent.parent;
|
|
24
|
-
}
|
|
25
|
-
throw new Error("Could not find context in parent components");
|
|
26
|
-
},
|
|
27
|
-
};
|
|
28
|
-
return context;
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAsync.test.d.ts","sourceRoot":"","sources":["../src/createAsync.test.ts"],"names":[],"mappings":""}
|
package/dist/createAsync.test.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { createAsync } from './createAsync';
|
|
3
|
-
describe('createAsync', () => {
|
|
4
|
-
it('should start in pending state', () => {
|
|
5
|
-
const promise = new Promise(() => { });
|
|
6
|
-
const async = createAsync(promise);
|
|
7
|
-
expect(async.isPending).toBe(true);
|
|
8
|
-
expect(async.value).toBeNull();
|
|
9
|
-
expect(async.error).toBeNull();
|
|
10
|
-
});
|
|
11
|
-
it('should resolve to value state on success', async () => {
|
|
12
|
-
const promise = Promise.resolve('success');
|
|
13
|
-
const async = createAsync(promise);
|
|
14
|
-
expect(async.isPending).toBe(true);
|
|
15
|
-
await promise;
|
|
16
|
-
// Wait for state update
|
|
17
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
18
|
-
expect(async.isPending).toBe(false);
|
|
19
|
-
expect(async.value).toBe('success');
|
|
20
|
-
expect(async.error).toBeNull();
|
|
21
|
-
});
|
|
22
|
-
it('should resolve to error state on rejection', async () => {
|
|
23
|
-
const promise = Promise.reject(new Error('failed'));
|
|
24
|
-
const async = createAsync(promise);
|
|
25
|
-
expect(async.isPending).toBe(true);
|
|
26
|
-
try {
|
|
27
|
-
await promise;
|
|
28
|
-
}
|
|
29
|
-
catch {
|
|
30
|
-
// Ignore
|
|
31
|
-
}
|
|
32
|
-
// Wait for state update
|
|
33
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
34
|
-
expect(async.isPending).toBe(false);
|
|
35
|
-
expect(async.value).toBeNull();
|
|
36
|
-
expect(async.error).toContain('failed');
|
|
37
|
-
});
|
|
38
|
-
it('should handle numeric values', async () => {
|
|
39
|
-
const promise = Promise.resolve(42);
|
|
40
|
-
const async = createAsync(promise);
|
|
41
|
-
await promise;
|
|
42
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
43
|
-
expect(async.value).toBe(42);
|
|
44
|
-
});
|
|
45
|
-
it('should handle object values', async () => {
|
|
46
|
-
const data = { id: 1, name: 'Test' };
|
|
47
|
-
const promise = Promise.resolve(data);
|
|
48
|
-
const async = createAsync(promise);
|
|
49
|
-
await promise;
|
|
50
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
51
|
-
expect(async.value).toEqual(data);
|
|
52
|
-
});
|
|
53
|
-
it('should handle array values', async () => {
|
|
54
|
-
const data = [1, 2, 3, 4, 5];
|
|
55
|
-
const promise = Promise.resolve(data);
|
|
56
|
-
const async = createAsync(promise);
|
|
57
|
-
await promise;
|
|
58
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
59
|
-
expect(async.value).toEqual(data);
|
|
60
|
-
});
|
|
61
|
-
it('should convert error to string', async () => {
|
|
62
|
-
const promise = Promise.reject('string error');
|
|
63
|
-
const async = createAsync(promise);
|
|
64
|
-
try {
|
|
65
|
-
await promise;
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
// Ignore
|
|
69
|
-
}
|
|
70
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
71
|
-
expect(typeof async.error).toBe('string');
|
|
72
|
-
expect(async.error).toBe('string error');
|
|
73
|
-
});
|
|
74
|
-
it('should handle error objects', async () => {
|
|
75
|
-
const error = new Error('Something went wrong');
|
|
76
|
-
const promise = Promise.reject(error);
|
|
77
|
-
const async = createAsync(promise);
|
|
78
|
-
try {
|
|
79
|
-
await promise;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// Ignore
|
|
83
|
-
}
|
|
84
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
85
|
-
expect(async.error).toContain('Something went wrong');
|
|
86
|
-
});
|
|
87
|
-
it('should create reactive state', async () => {
|
|
88
|
-
const promise = new Promise((resolve) => {
|
|
89
|
-
setTimeout(() => resolve('delayed'), 10);
|
|
90
|
-
});
|
|
91
|
-
const async = createAsync(promise);
|
|
92
|
-
expect(async.isPending).toBe(true);
|
|
93
|
-
await promise;
|
|
94
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
95
|
-
expect(async.isPending).toBe(false);
|
|
96
|
-
expect(async.value).toBe('delayed');
|
|
97
|
-
});
|
|
98
|
-
it('should handle immediate resolution', async () => {
|
|
99
|
-
const async = createAsync(Promise.resolve('immediate'));
|
|
100
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
101
|
-
expect(async.isPending).toBe(false);
|
|
102
|
-
expect(async.value).toBe('immediate');
|
|
103
|
-
});
|
|
104
|
-
it('should handle immediate rejection', async () => {
|
|
105
|
-
const async = createAsync(Promise.reject('immediate error'));
|
|
106
|
-
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
107
|
-
expect(async.isPending).toBe(false);
|
|
108
|
-
expect(async.error).toBe('immediate error');
|
|
109
|
-
});
|
|
110
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
type AsyncState<T> = {
|
|
2
|
-
isPending: true;
|
|
3
|
-
value: null;
|
|
4
|
-
error: null;
|
|
5
|
-
} | {
|
|
6
|
-
isPending: false;
|
|
7
|
-
value: T;
|
|
8
|
-
error: null;
|
|
9
|
-
} | {
|
|
10
|
-
isPending: false;
|
|
11
|
-
value: null;
|
|
12
|
-
error: string;
|
|
13
|
-
};
|
|
14
|
-
export declare function createAsyncState<T>(promise: Promise<T>): AsyncState<T>;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=createAsyncState.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncState.d.ts","sourceRoot":"","sources":["../src/createAsyncState.ts"],"names":[],"mappings":"AAEA,KAAK,UAAU,CAAC,CAAC,IACb;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC;IACT,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEN,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,iBAwBtD"}
|
package/dist/createAsyncState.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createState } from "./createState";
|
|
2
|
-
export function createAsyncState(promise) {
|
|
3
|
-
const state = createState({
|
|
4
|
-
isPending: true,
|
|
5
|
-
error: null,
|
|
6
|
-
value: null,
|
|
7
|
-
});
|
|
8
|
-
promise
|
|
9
|
-
.then((value) => {
|
|
10
|
-
Object.assign(state, {
|
|
11
|
-
value,
|
|
12
|
-
error: null,
|
|
13
|
-
isPending: false,
|
|
14
|
-
});
|
|
15
|
-
})
|
|
16
|
-
.catch((error) => {
|
|
17
|
-
Object.assign(state, {
|
|
18
|
-
value: null,
|
|
19
|
-
error: String(error),
|
|
20
|
-
isPending: false,
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
return state;
|
|
24
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.test.d.ts","sourceRoot":"","sources":["../src/createContext.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "./jsx-runtime";
|
|
2
|
-
import { describe, it, expect } from "vitest";
|
|
3
|
-
import { createContext } from "./createContext";
|
|
4
|
-
import { render } from "./vdom";
|
|
5
|
-
describe("createContext", () => {
|
|
6
|
-
it("should create a context object", () => {
|
|
7
|
-
const context = createContext();
|
|
8
|
-
expect(context).toHaveProperty("inject");
|
|
9
|
-
expect(context).toHaveProperty("get");
|
|
10
|
-
});
|
|
11
|
-
it("should allow setting and getting context values", () => {
|
|
12
|
-
const ThemeContext = createContext();
|
|
13
|
-
function Parent() {
|
|
14
|
-
ThemeContext.inject({ theme: "dark" });
|
|
15
|
-
return () => _jsx(Child, {});
|
|
16
|
-
}
|
|
17
|
-
function Child() {
|
|
18
|
-
const theme = ThemeContext.get();
|
|
19
|
-
return () => _jsx("div", { children: theme.theme });
|
|
20
|
-
}
|
|
21
|
-
const container = document.createElement("div");
|
|
22
|
-
document.body.appendChild(container);
|
|
23
|
-
const vnode = render(_jsx(Parent, {}), container);
|
|
24
|
-
expect(vnode.elm.textContent).toContain("dark");
|
|
25
|
-
document.body.removeChild(vnode.elm);
|
|
26
|
-
});
|
|
27
|
-
it("should traverse parent components to find context", () => {
|
|
28
|
-
const ThemeContext = createContext();
|
|
29
|
-
function GrandParent() {
|
|
30
|
-
ThemeContext.inject({ theme: "light" });
|
|
31
|
-
return () => _jsx(Parent, {});
|
|
32
|
-
}
|
|
33
|
-
function Parent() {
|
|
34
|
-
return () => _jsx(Child, {});
|
|
35
|
-
}
|
|
36
|
-
function Child() {
|
|
37
|
-
const theme = ThemeContext.get();
|
|
38
|
-
return () => _jsx("div", { children: theme.theme });
|
|
39
|
-
}
|
|
40
|
-
const container = document.createElement("div");
|
|
41
|
-
document.body.appendChild(container);
|
|
42
|
-
const vnode = render(_jsx(GrandParent, {}), container);
|
|
43
|
-
expect(vnode.elm.textContent).toContain("light");
|
|
44
|
-
document.body.removeChild(vnode.elm);
|
|
45
|
-
});
|
|
46
|
-
it("should throw error when context is not found", () => {
|
|
47
|
-
const ThemeContext = createContext();
|
|
48
|
-
function Child() {
|
|
49
|
-
expect(() => {
|
|
50
|
-
ThemeContext.get();
|
|
51
|
-
}).toThrow("Could not find context in parent components");
|
|
52
|
-
return () => _jsx("div", { children: "Child" });
|
|
53
|
-
}
|
|
54
|
-
const container = document.createElement("div");
|
|
55
|
-
document.body.appendChild(container);
|
|
56
|
-
const vnode = render(_jsx(Child, {}), container);
|
|
57
|
-
document.body.removeChild(vnode.elm);
|
|
58
|
-
});
|
|
59
|
-
it("should throw error when setting context outside component", () => {
|
|
60
|
-
const ThemeContext = createContext();
|
|
61
|
-
expect(() => {
|
|
62
|
-
ThemeContext.inject({ theme: "dark" });
|
|
63
|
-
}).toThrow("No current root");
|
|
64
|
-
});
|
|
65
|
-
it("should throw error when getting context outside component", () => {
|
|
66
|
-
const ThemeContext = createContext();
|
|
67
|
-
expect(() => {
|
|
68
|
-
ThemeContext.get();
|
|
69
|
-
}).toThrow("No current root");
|
|
70
|
-
});
|
|
71
|
-
it("should allow overriding context in nested components", () => {
|
|
72
|
-
const ThemeContext = createContext();
|
|
73
|
-
function GrandParent() {
|
|
74
|
-
ThemeContext.inject({ theme: "light" });
|
|
75
|
-
return () => (_jsxs("div", { children: [_jsx(Parent, {}), _jsx(ChildOfGrandParent, {})] }));
|
|
76
|
-
}
|
|
77
|
-
function Parent() {
|
|
78
|
-
ThemeContext.inject({ theme: "dark" });
|
|
79
|
-
return () => _jsx(ChildOfParent, {});
|
|
80
|
-
}
|
|
81
|
-
function ChildOfParent() {
|
|
82
|
-
const theme = ThemeContext.get();
|
|
83
|
-
return () => _jsx("div", { class: "child-of-parent", children: theme.theme });
|
|
84
|
-
}
|
|
85
|
-
function ChildOfGrandParent() {
|
|
86
|
-
const theme = ThemeContext.get();
|
|
87
|
-
return () => _jsx("div", { class: "child-of-grandparent", children: theme.theme });
|
|
88
|
-
}
|
|
89
|
-
const container = document.createElement("div");
|
|
90
|
-
document.body.appendChild(container);
|
|
91
|
-
const vnode = render(_jsx(GrandParent, {}), container);
|
|
92
|
-
const childOfParent = document.querySelector(".child-of-parent");
|
|
93
|
-
const childOfGrandParent = document.querySelector(".child-of-grandparent");
|
|
94
|
-
expect(childOfParent?.textContent).toBe("dark");
|
|
95
|
-
expect(childOfGrandParent?.textContent).toBe("light");
|
|
96
|
-
document.body.removeChild(vnode.elm);
|
|
97
|
-
});
|
|
98
|
-
it("should support multiple different contexts", () => {
|
|
99
|
-
const ThemeContext = createContext();
|
|
100
|
-
const UserContext = createContext();
|
|
101
|
-
function Parent() {
|
|
102
|
-
ThemeContext.inject({ theme: "dark" });
|
|
103
|
-
UserContext.inject({ name: "Alice" });
|
|
104
|
-
return () => _jsx(Child, {});
|
|
105
|
-
}
|
|
106
|
-
function Child() {
|
|
107
|
-
const theme = ThemeContext.get();
|
|
108
|
-
const user = UserContext.get();
|
|
109
|
-
return () => (_jsxs("div", { children: [theme.theme, " - ", user.name] }));
|
|
110
|
-
}
|
|
111
|
-
const container = document.createElement("div");
|
|
112
|
-
document.body.appendChild(container);
|
|
113
|
-
const vnode = render(_jsx(Parent, {}), container);
|
|
114
|
-
expect(vnode.elm.textContent).toContain("dark - Alice");
|
|
115
|
-
document.body.removeChild(vnode.elm);
|
|
116
|
-
});
|
|
117
|
-
it("should handle context values of different types", () => {
|
|
118
|
-
const NumberContext = createContext();
|
|
119
|
-
const ArrayContext = createContext();
|
|
120
|
-
function Parent() {
|
|
121
|
-
NumberContext.inject(42);
|
|
122
|
-
ArrayContext.inject(["a", "b", "c"]);
|
|
123
|
-
return () => _jsx(Child, {});
|
|
124
|
-
}
|
|
125
|
-
function Child() {
|
|
126
|
-
const num = NumberContext.get();
|
|
127
|
-
const arr = ArrayContext.get();
|
|
128
|
-
return () => (_jsxs("div", { children: [num, " - ", arr.join(",")] }));
|
|
129
|
-
}
|
|
130
|
-
const container = document.createElement("div");
|
|
131
|
-
document.body.appendChild(container);
|
|
132
|
-
const vnode = render(_jsx(Parent, {}), container);
|
|
133
|
-
expect(vnode.elm.textContent).toContain("42 - a,b,c");
|
|
134
|
-
document.body.removeChild(vnode.elm);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createMutation.test.d.ts","sourceRoot":"","sources":["../src/createMutation.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { createMutation } from './createMutation';
|
|
3
|
-
describe('createMutation', () => {
|
|
4
|
-
it('should start in idle state', () => {
|
|
5
|
-
const mutator = vi.fn(() => Promise.resolve(null));
|
|
6
|
-
const mutation = createMutation(mutator);
|
|
7
|
-
expect(mutation.isPending).toBe(false);
|
|
8
|
-
expect(mutation.params).toBeNull();
|
|
9
|
-
expect(mutation.error).toBeNull();
|
|
10
|
-
expect(mutator).not.toHaveBeenCalled();
|
|
11
|
-
});
|
|
12
|
-
it('should execute mutator when mutate is called', async () => {
|
|
13
|
-
const mutator = vi.fn((params) => Promise.resolve(params));
|
|
14
|
-
const mutation = createMutation(mutator);
|
|
15
|
-
mutation.mutate('test');
|
|
16
|
-
expect(mutation.isPending).toBe(true);
|
|
17
|
-
expect(mutation.params).toBe('test');
|
|
18
|
-
expect(mutator).toHaveBeenCalledWith('test');
|
|
19
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
20
|
-
expect(mutation.isPending).toBe(false);
|
|
21
|
-
expect(mutation.params).toBeNull();
|
|
22
|
-
});
|
|
23
|
-
it('should handle successful mutations', async () => {
|
|
24
|
-
const mutator = (params) => Promise.resolve(params);
|
|
25
|
-
const mutation = createMutation(mutator);
|
|
26
|
-
mutation.mutate({ id: 1 });
|
|
27
|
-
expect(mutation.isPending).toBe(true);
|
|
28
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
29
|
-
expect(mutation.isPending).toBe(false);
|
|
30
|
-
expect(mutation.error).toBeNull();
|
|
31
|
-
expect(mutation.params).toBeNull();
|
|
32
|
-
});
|
|
33
|
-
it('should handle mutation errors', async () => {
|
|
34
|
-
const mutator = (params) => Promise.reject(new Error('Mutation failed'));
|
|
35
|
-
const mutation = createMutation(mutator);
|
|
36
|
-
mutation.mutate('test');
|
|
37
|
-
expect(mutation.isPending).toBe(true);
|
|
38
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
39
|
-
expect(mutation.isPending).toBe(false);
|
|
40
|
-
expect(mutation.error).toContain('Mutation failed');
|
|
41
|
-
expect(mutation.params).toBeNull();
|
|
42
|
-
});
|
|
43
|
-
it('should cancel previous mutation on new mutate call', async () => {
|
|
44
|
-
let resolveFirst;
|
|
45
|
-
let resolveSecond;
|
|
46
|
-
const firstPromise = new Promise((resolve) => {
|
|
47
|
-
resolveFirst = resolve;
|
|
48
|
-
});
|
|
49
|
-
const secondPromise = new Promise((resolve) => {
|
|
50
|
-
resolveSecond = resolve;
|
|
51
|
-
});
|
|
52
|
-
const mutator = vi
|
|
53
|
-
.fn()
|
|
54
|
-
.mockReturnValueOnce(firstPromise)
|
|
55
|
-
.mockReturnValueOnce(secondPromise);
|
|
56
|
-
const mutation = createMutation(mutator);
|
|
57
|
-
mutation.mutate('first');
|
|
58
|
-
expect(mutation.params).toBe('first');
|
|
59
|
-
// Trigger second mutation before first completes
|
|
60
|
-
mutation.mutate('second');
|
|
61
|
-
expect(mutation.params).toBe('second');
|
|
62
|
-
// Resolve first (should be ignored due to cancellation)
|
|
63
|
-
resolveFirst('first');
|
|
64
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
65
|
-
expect(mutation.isPending).toBe(true); // Still pending second
|
|
66
|
-
// Resolve second
|
|
67
|
-
resolveSecond('second');
|
|
68
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
69
|
-
expect(mutation.isPending).toBe(false);
|
|
70
|
-
expect(mutation.params).toBeNull();
|
|
71
|
-
});
|
|
72
|
-
it('should handle rapid successive mutations', async () => {
|
|
73
|
-
let counter = 0;
|
|
74
|
-
const mutator = vi.fn(() => Promise.resolve(++counter));
|
|
75
|
-
const mutation = createMutation(mutator);
|
|
76
|
-
// Rapid mutations
|
|
77
|
-
mutation.mutate('1');
|
|
78
|
-
mutation.mutate('2');
|
|
79
|
-
mutation.mutate('3');
|
|
80
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
81
|
-
// Only the last mutation should complete
|
|
82
|
-
expect(mutator).toHaveBeenCalledTimes(3);
|
|
83
|
-
expect(mutation.isPending).toBe(false);
|
|
84
|
-
expect(mutation.params).toBeNull();
|
|
85
|
-
});
|
|
86
|
-
it('should clear error on successful retry', async () => {
|
|
87
|
-
const mutator = vi
|
|
88
|
-
.fn()
|
|
89
|
-
.mockRejectedValueOnce(new Error('First error'))
|
|
90
|
-
.mockResolvedValueOnce('success');
|
|
91
|
-
const mutation = createMutation(mutator);
|
|
92
|
-
mutation.mutate('attempt1');
|
|
93
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
94
|
-
expect(mutation.error).toContain('First error');
|
|
95
|
-
mutation.mutate('attempt2');
|
|
96
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
97
|
-
expect(mutation.error).toBeNull();
|
|
98
|
-
expect(mutation.isPending).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
it('should handle different parameter types', async () => {
|
|
101
|
-
const mutator = vi.fn((params) => Promise.resolve(params));
|
|
102
|
-
const mutation = createMutation(mutator);
|
|
103
|
-
// Object params
|
|
104
|
-
mutation.mutate({ id: 1, name: 'test' });
|
|
105
|
-
expect(mutation.params).toEqual({ id: 1, name: 'test' });
|
|
106
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
107
|
-
// Array params
|
|
108
|
-
const mutation2 = createMutation(mutator);
|
|
109
|
-
mutation2.mutate([1, 2, 3]);
|
|
110
|
-
expect(mutation2.params).toEqual([1, 2, 3]);
|
|
111
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
112
|
-
// String params
|
|
113
|
-
const mutation3 = createMutation(mutator);
|
|
114
|
-
mutation3.mutate('string');
|
|
115
|
-
expect(mutation3.params).toBe('string');
|
|
116
|
-
});
|
|
117
|
-
it('should convert errors to strings', async () => {
|
|
118
|
-
const mutator = (params) => Promise.reject('string error');
|
|
119
|
-
const mutation = createMutation(mutator);
|
|
120
|
-
mutation.mutate('test');
|
|
121
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
122
|
-
expect(typeof mutation.error).toBe('string');
|
|
123
|
-
expect(mutation.error).toBe('string error');
|
|
124
|
-
});
|
|
125
|
-
it('should handle AbortController cancellation correctly', async () => {
|
|
126
|
-
const abortedPromise = new Promise((_, reject) => {
|
|
127
|
-
const error = new Error('Aborted');
|
|
128
|
-
error.name = 'AbortError';
|
|
129
|
-
setTimeout(() => reject(error), 5);
|
|
130
|
-
});
|
|
131
|
-
const successPromise = Promise.resolve('success');
|
|
132
|
-
const mutator = vi
|
|
133
|
-
.fn()
|
|
134
|
-
.mockReturnValueOnce(abortedPromise)
|
|
135
|
-
.mockReturnValueOnce(successPromise);
|
|
136
|
-
const mutation = createMutation(mutator);
|
|
137
|
-
mutation.mutate('first');
|
|
138
|
-
// Immediately trigger second mutation to abort first
|
|
139
|
-
mutation.mutate('second');
|
|
140
|
-
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
141
|
-
expect(mutation.isPending).toBe(false);
|
|
142
|
-
expect(mutation.error).toBeNull();
|
|
143
|
-
});
|
|
144
|
-
it('should track params during pending state', () => {
|
|
145
|
-
const mutator = () => new Promise((resolve) => setTimeout(() => resolve(null), 100));
|
|
146
|
-
const mutation = createMutation(mutator);
|
|
147
|
-
const params = { id: 123, action: 'update' };
|
|
148
|
-
mutation.mutate(params);
|
|
149
|
-
expect(mutation.isPending).toBe(true);
|
|
150
|
-
expect(mutation.params).toEqual(params);
|
|
151
|
-
});
|
|
152
|
-
it('should expose reactive getters', async () => {
|
|
153
|
-
const mutator = () => Promise.resolve('data');
|
|
154
|
-
const mutation = createMutation(mutator);
|
|
155
|
-
// Access getters before mutation
|
|
156
|
-
expect(mutation.isPending).toBe(false);
|
|
157
|
-
expect(mutation.params).toBeNull();
|
|
158
|
-
expect(mutation.error).toBeNull();
|
|
159
|
-
mutation.mutate('test');
|
|
160
|
-
// Access getters during mutation
|
|
161
|
-
expect(mutation.isPending).toBe(true);
|
|
162
|
-
expect(mutation.params).toBe('test');
|
|
163
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
164
|
-
// Access getters after mutation
|
|
165
|
-
expect(mutation.isPending).toBe(false);
|
|
166
|
-
expect(mutation.params).toBeNull();
|
|
167
|
-
});
|
|
168
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createQuery.test.d.ts","sourceRoot":"","sources":["../src/createQuery.test.ts"],"names":[],"mappings":""}
|