rask-ui 0.16.0 → 0.18.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.
- package/README.md +1 -1
- package/dist/batch.d.ts.map +1 -1
- package/dist/batch.js +15 -18
- package/dist/component.d.ts +13 -11
- package/dist/component.d.ts.map +1 -1
- package/dist/component.js +88 -82
- package/dist/createContext.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/tests/createEffect.test.js +435 -422
- package/dist/useAsync.js +1 -1
- package/dist/useDerived.d.ts +5 -0
- package/dist/useDerived.d.ts.map +1 -0
- package/dist/useDerived.js +72 -0
- package/dist/useEffect.js +1 -1
- package/dist/useRef.d.ts.map +1 -1
- package/dist/useRef.js +5 -0
- package/dist/useRouter.js +1 -1
- package/dist/useState.d.ts +2 -2
- package/dist/useState.js +3 -3
- package/dist/useView.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ RASK provides a set of reactive hooks for building interactive UIs. These hooks
|
|
|
47
47
|
|
|
48
48
|
- **`useState`** - Create reactive state objects
|
|
49
49
|
- **`useEffect`** - Run side effects when dependencies change
|
|
50
|
-
- **`
|
|
50
|
+
- **`useDerived`** - Derive values from state with automatic caching
|
|
51
51
|
- **`useAsync`** - Manage async operations (fetch, mutations, polling, etc.)
|
|
52
52
|
- **`useRouter`** - Type-safe client-side routing
|
|
53
53
|
- **`createContext`** / **`useContext`** - Share data through the component tree
|
package/dist/batch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../src/batch.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AA+BlE,wBAAgB,KAAK,CAAC,EAAE,EAAE,cAAc,QAgBvC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,QA4BvC"}
|
package/dist/batch.js
CHANGED
|
@@ -23,23 +23,9 @@ function flushAsyncQueue() {
|
|
|
23
23
|
}
|
|
24
24
|
asyncQueue.length = 0;
|
|
25
25
|
}
|
|
26
|
-
function flushSyncQueue(queue) {
|
|
27
|
-
if (!queue.length)
|
|
28
|
-
return;
|
|
29
|
-
// No snapshot, just iterate.
|
|
30
|
-
// New callbacks queued via nested syncBatch will create
|
|
31
|
-
// their own queue on the stack and flush independently.
|
|
32
|
-
for (let i = 0; i < queue.length; i++) {
|
|
33
|
-
const cb = queue[i];
|
|
34
|
-
queue[i] = undefined;
|
|
35
|
-
cb();
|
|
36
|
-
cb.__queued = false;
|
|
37
|
-
}
|
|
38
|
-
queue.length = 0;
|
|
39
|
-
}
|
|
40
26
|
export function queue(cb) {
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
if (cb.__queued)
|
|
28
|
+
return;
|
|
43
29
|
cb.__queued = true;
|
|
44
30
|
// If we're in a sync batch, push to the current sync queue
|
|
45
31
|
if (syncQueueStack.length) {
|
|
@@ -64,7 +50,18 @@ export function syncBatch(cb) {
|
|
|
64
50
|
syncQueueStack.pop();
|
|
65
51
|
throw e;
|
|
66
52
|
}
|
|
67
|
-
//
|
|
53
|
+
// Keep flushing while queue has work.
|
|
54
|
+
// This handles cascading updates (e.g., derived signals notifying their observers).
|
|
55
|
+
// The queue stays on the stack so any new notifications get added to it.
|
|
56
|
+
while (queue.length > 0) {
|
|
57
|
+
for (let i = 0; i < queue.length; i++) {
|
|
58
|
+
const cb = queue[i];
|
|
59
|
+
queue[i] = undefined;
|
|
60
|
+
cb();
|
|
61
|
+
cb.__queued = false;
|
|
62
|
+
}
|
|
63
|
+
queue.length = 0;
|
|
64
|
+
}
|
|
65
|
+
// Pop the queue after everything is flushed
|
|
68
66
|
syncQueueStack.pop();
|
|
69
|
-
flushSyncQueue(queue);
|
|
70
67
|
}
|
package/dist/component.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { VNode, Component, Props } from "inferno";
|
|
1
|
+
import { VNode, Component, Props, InfernoNode } from "inferno";
|
|
2
2
|
import { Observer } from "./observation";
|
|
3
3
|
export type RaskStatelessFunctionComponent<P extends Props<any>> = (() => VNode) | ((props: P) => VNode);
|
|
4
4
|
export declare class RaskStatelessComponent extends Component {
|
|
5
5
|
renderFn: RaskStatelessFunctionComponent<any>;
|
|
6
|
+
private isNotified;
|
|
7
|
+
private isReconciling;
|
|
6
8
|
observer: Observer;
|
|
7
|
-
|
|
9
|
+
private reactiveProps;
|
|
10
|
+
shouldComponentUpdate(): boolean;
|
|
11
|
+
componentWillReceiveProps(nextProps: any): void;
|
|
8
12
|
render(): VNode;
|
|
9
13
|
}
|
|
10
14
|
export declare function getCurrentComponent(): RaskStatefulComponent<any> | undefined;
|
|
@@ -15,10 +19,10 @@ export declare class RaskStatefulComponent<P extends Props<any>> extends Compone
|
|
|
15
19
|
setup: RaskStatefulFunctionComponent<P>;
|
|
16
20
|
private renderFn?;
|
|
17
21
|
private reactiveProps?;
|
|
18
|
-
private
|
|
22
|
+
private isNotified;
|
|
23
|
+
private isReconciling;
|
|
24
|
+
observer: Observer;
|
|
19
25
|
isRendering: boolean;
|
|
20
|
-
private willRender;
|
|
21
|
-
private nextProps;
|
|
22
26
|
effects: Array<{
|
|
23
27
|
isDirty: boolean;
|
|
24
28
|
run: () => void;
|
|
@@ -27,14 +31,12 @@ export declare class RaskStatefulComponent<P extends Props<any>> extends Compone
|
|
|
27
31
|
getChildContext(): any;
|
|
28
32
|
onMounts: Array<() => void>;
|
|
29
33
|
onCleanups: Array<() => void>;
|
|
30
|
-
private createReactiveProps;
|
|
31
34
|
componentDidMount(): void;
|
|
32
35
|
componentWillUnmount(): void;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
shouldComponentUpdate(nextProps: Props<any>): boolean;
|
|
36
|
+
componentWillReceiveProps(nextProps: Readonly<{
|
|
37
|
+
children?: InfernoNode;
|
|
38
|
+
} & P>): void;
|
|
39
|
+
shouldComponentUpdate(): boolean;
|
|
38
40
|
render(): any;
|
|
39
41
|
}
|
|
40
42
|
export declare function createComponent(props: Props<any>, key?: string): VNode;
|
package/dist/component.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"component.d.ts","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EACL,SAAS,EACT,KAAK,EACL,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAsB,QAAQ,EAAU,MAAM,eAAe,CAAC;AAIrE,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAC3D,CAAC,MAAM,KAAK,CAAC,GACb,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC;AAE1B,qBAAa,sBAAuB,SAAQ,SAAS;IAC3C,QAAQ,EAAE,8BAA8B,CAAC,GAAG,CAAC,CAAC;IACtD,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;IAC9B,QAAQ,WAML;IACH,OAAO,CAAC,aAAa,CAAc;IAEnC,qBAAqB,IAAI,OAAO;IAMhC,yBAAyB,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI;IAc/C,MAAM;CAWP;AAID,wBAAgB,mBAAmB,2CAElC;AAED,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,IAAI,QAM5C;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,IAAI,QAMxC;AAED,MAAM,MAAM,6BAA6B,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAC1D,CAAC,MAAM,MAAM,KAAK,CAAC,GACnB,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,KAAK,CAAC,CAAC;AAEhC,qBAAa,qBAAqB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IACnE,KAAK,EAAE,6BAA6B,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,CAAC,QAAQ,CAAC,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAC,CAAa;IACnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;IAC9B,QAAQ,WAOL;IAEH,WAAW,UAAS;IACpB,OAAO,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,MAAM,IAAI,CAAA;KAAE,CAAC,CAAM;IAC3D,QAAQ,gBAAa;IACrB,eAAe;IAUf,QAAQ,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IACjC,UAAU,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IAEnC,iBAAiB,IAAI,IAAI;IAGzB,oBAAoB,IAAI,IAAI;IAI5B,yBAAyB,CACvB,SAAS,EAAE,QAAQ,CAAC;QAAE,QAAQ,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,CAAC,CAAC,GAClD,IAAI;IAcP,qBAAqB,IAAI,OAAO;IAMhC,MAAM;CAyCP;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,SAO9D"}
|
package/dist/component.js
CHANGED
|
@@ -1,21 +1,41 @@
|
|
|
1
|
-
import { createComponentVNode, Component } from "inferno";
|
|
1
|
+
import { createComponentVNode, Component, } from "inferno";
|
|
2
2
|
import { getCurrentObserver, Observer, Signal } from "./observation";
|
|
3
3
|
import { syncBatch } from "./batch";
|
|
4
4
|
import { PROXY_MARKER } from "./useState";
|
|
5
5
|
export class RaskStatelessComponent extends Component {
|
|
6
|
+
isNotified = false;
|
|
7
|
+
isReconciling = false;
|
|
6
8
|
observer = new Observer(() => {
|
|
9
|
+
if (this.isReconciling) {
|
|
10
|
+
this.isNotified = true;
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
7
13
|
this.forceUpdate();
|
|
8
14
|
});
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
reactiveProps;
|
|
16
|
+
shouldComponentUpdate() {
|
|
17
|
+
const shouldRender = this.isNotified;
|
|
18
|
+
this.isNotified = false;
|
|
19
|
+
this.isReconciling = false;
|
|
20
|
+
return shouldRender;
|
|
21
|
+
}
|
|
22
|
+
componentWillReceiveProps(nextProps) {
|
|
23
|
+
this.isReconciling = true;
|
|
24
|
+
syncBatch(() => {
|
|
25
|
+
for (const prop in nextProps) {
|
|
26
|
+
if (this.props[prop] === nextProps[prop]) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
this.reactiveProps[prop] = nextProps[prop];
|
|
14
31
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
32
|
+
});
|
|
33
|
+
this.props = nextProps;
|
|
17
34
|
}
|
|
18
35
|
render() {
|
|
36
|
+
if (!this.reactiveProps) {
|
|
37
|
+
this.reactiveProps = createReactiveProps(this);
|
|
38
|
+
}
|
|
19
39
|
const stopObserving = this.observer.observe();
|
|
20
40
|
const result = this.renderFn(this.props);
|
|
21
41
|
stopObserving();
|
|
@@ -28,32 +48,30 @@ export function getCurrentComponent() {
|
|
|
28
48
|
}
|
|
29
49
|
export function useMountEffect(cb) {
|
|
30
50
|
if (!currentComponent) {
|
|
31
|
-
throw new Error("Only use
|
|
51
|
+
throw new Error("Only use useMountEffect in component setup");
|
|
32
52
|
}
|
|
33
53
|
currentComponent.onMounts.push(cb);
|
|
34
54
|
}
|
|
35
55
|
export function useCleanup(cb) {
|
|
36
56
|
if (!currentComponent || currentComponent.isRendering) {
|
|
37
|
-
throw new Error("Only use
|
|
57
|
+
throw new Error("Only use useCleanup in component setup");
|
|
38
58
|
}
|
|
39
59
|
currentComponent.onCleanups.push(cb);
|
|
40
60
|
}
|
|
41
61
|
export class RaskStatefulComponent extends Component {
|
|
42
62
|
renderFn;
|
|
43
63
|
reactiveProps;
|
|
64
|
+
isNotified = false;
|
|
65
|
+
isReconciling = false;
|
|
44
66
|
observer = new Observer(() => {
|
|
45
|
-
if (this.
|
|
67
|
+
if (this.isReconciling) {
|
|
68
|
+
this.isNotified = true;
|
|
46
69
|
return;
|
|
47
70
|
}
|
|
48
71
|
this.forceUpdate();
|
|
49
72
|
});
|
|
50
73
|
// Flag to prevent props from tracking in render scope (We use props reconciliation)
|
|
51
74
|
isRendering = false;
|
|
52
|
-
// Flag to prevent observer notifications to cause render during reconciliation
|
|
53
|
-
willRender = true;
|
|
54
|
-
// Since reactive props updates before the reconciliation (without causing a new one), we
|
|
55
|
-
// need to return these from the reactive props
|
|
56
|
-
nextProps = this.props;
|
|
57
75
|
effects = [];
|
|
58
76
|
contexts = new Map();
|
|
59
77
|
getChildContext() {
|
|
@@ -67,90 +85,35 @@ export class RaskStatefulComponent extends Component {
|
|
|
67
85
|
}
|
|
68
86
|
onMounts = [];
|
|
69
87
|
onCleanups = [];
|
|
70
|
-
createReactiveProps() {
|
|
71
|
-
const reactiveProps = {};
|
|
72
|
-
const self = this;
|
|
73
|
-
const signals = new Map();
|
|
74
|
-
for (const prop in this.nextProps) {
|
|
75
|
-
const value = this.nextProps[prop];
|
|
76
|
-
// Skip known non-reactive props
|
|
77
|
-
if (prop === "key" || prop === "ref") {
|
|
78
|
-
reactiveProps[prop] = value;
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
// Skip objects/arrays - they're already reactive if they're proxies
|
|
82
|
-
// No need to wrap them in additional signals
|
|
83
|
-
if (typeof value === "object" &&
|
|
84
|
-
value !== null &&
|
|
85
|
-
PROXY_MARKER in value) {
|
|
86
|
-
reactiveProps[prop] = value;
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
// Only create reactive getters for primitives
|
|
90
|
-
Object.defineProperty(reactiveProps, prop, {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get() {
|
|
93
|
-
const observer = getCurrentObserver();
|
|
94
|
-
if (!self.isRendering && observer) {
|
|
95
|
-
// Lazy create signal only when accessed in reactive context
|
|
96
|
-
let signal = signals.get(prop);
|
|
97
|
-
if (!signal) {
|
|
98
|
-
signal = new Signal();
|
|
99
|
-
signals.set(prop, signal);
|
|
100
|
-
}
|
|
101
|
-
observer.subscribeSignal(signal);
|
|
102
|
-
}
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
return self.nextProps[prop];
|
|
105
|
-
},
|
|
106
|
-
set(value) {
|
|
107
|
-
// Only notify if signal was created (i.e., prop was accessed reactively)
|
|
108
|
-
const signal = signals.get(prop);
|
|
109
|
-
if (signal) {
|
|
110
|
-
signal.notify();
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return reactiveProps;
|
|
116
|
-
}
|
|
117
88
|
componentDidMount() {
|
|
118
89
|
this.onMounts.forEach((cb) => cb());
|
|
119
90
|
}
|
|
120
91
|
componentWillUnmount() {
|
|
121
92
|
this.onCleanups.forEach((cb) => cb());
|
|
122
93
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*/
|
|
126
|
-
componentWillUpdate(nextProps) {
|
|
127
|
-
this.willRender = true;
|
|
128
|
-
this.nextProps = nextProps;
|
|
94
|
+
componentWillReceiveProps(nextProps) {
|
|
95
|
+
this.isReconciling = true;
|
|
129
96
|
syncBatch(() => {
|
|
130
97
|
for (const prop in nextProps) {
|
|
131
|
-
if (prop ===
|
|
132
|
-
this.props[prop] === nextProps[prop]) {
|
|
98
|
+
if (this.props[prop] === nextProps[prop]) {
|
|
133
99
|
continue;
|
|
134
100
|
}
|
|
135
101
|
// @ts-ignore
|
|
136
102
|
this.reactiveProps[prop] = nextProps[prop];
|
|
137
103
|
}
|
|
138
104
|
});
|
|
105
|
+
this.props = nextProps;
|
|
139
106
|
}
|
|
140
|
-
shouldComponentUpdate(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return false;
|
|
107
|
+
shouldComponentUpdate() {
|
|
108
|
+
const shouldRender = this.isNotified;
|
|
109
|
+
this.isNotified = false;
|
|
110
|
+
this.isReconciling = false;
|
|
111
|
+
return shouldRender;
|
|
149
112
|
}
|
|
150
113
|
render() {
|
|
151
114
|
currentComponent = this;
|
|
152
115
|
if (!this.renderFn) {
|
|
153
|
-
this.reactiveProps =
|
|
116
|
+
this.reactiveProps = createReactiveProps(this);
|
|
154
117
|
try {
|
|
155
118
|
this.renderFn = this.setup(this.reactiveProps);
|
|
156
119
|
if (typeof this.renderFn !== "function") {
|
|
@@ -171,7 +134,6 @@ export class RaskStatefulComponent extends Component {
|
|
|
171
134
|
this.isRendering = true;
|
|
172
135
|
result = this.renderFn();
|
|
173
136
|
this.isRendering = false;
|
|
174
|
-
this.willRender = false;
|
|
175
137
|
}
|
|
176
138
|
catch (error) {
|
|
177
139
|
if (typeof this.context.notifyError !== "function") {
|
|
@@ -189,3 +151,47 @@ export class RaskStatefulComponent extends Component {
|
|
|
189
151
|
export function createComponent(props, key) {
|
|
190
152
|
return createComponentVNode(4 /* VNodeFlags.ComponentClass */, RaskStatefulComponent, props, key);
|
|
191
153
|
}
|
|
154
|
+
function createReactiveProps(comp) {
|
|
155
|
+
const reactiveProps = {};
|
|
156
|
+
const signals = new Map();
|
|
157
|
+
for (const prop in comp.props) {
|
|
158
|
+
const value = comp.props[prop];
|
|
159
|
+
// Skip known non-reactive props
|
|
160
|
+
if (prop === "key" || prop === "ref") {
|
|
161
|
+
reactiveProps[prop] = value;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
// Skip objects/arrays - they're already reactive if they're proxies
|
|
165
|
+
// No need to wrap them in additional signals
|
|
166
|
+
if (typeof value === "object" && value !== null && PROXY_MARKER in value) {
|
|
167
|
+
reactiveProps[prop] = value;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
// Only create reactive getters for primitives
|
|
171
|
+
Object.defineProperty(reactiveProps, prop, {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
get() {
|
|
174
|
+
const observer = getCurrentObserver();
|
|
175
|
+
if (observer) {
|
|
176
|
+
// Lazy create signal only when accessed in reactive context
|
|
177
|
+
let signal = signals.get(prop);
|
|
178
|
+
if (!signal) {
|
|
179
|
+
signal = new Signal();
|
|
180
|
+
signals.set(prop, signal);
|
|
181
|
+
}
|
|
182
|
+
observer.subscribeSignal(signal);
|
|
183
|
+
}
|
|
184
|
+
return comp.props[prop];
|
|
185
|
+
},
|
|
186
|
+
set(value) {
|
|
187
|
+
comp.props[prop] = value;
|
|
188
|
+
// Only notify if signal was created (i.e., prop was accessed reactively)
|
|
189
|
+
const signal = signals.get(prop);
|
|
190
|
+
if (signal) {
|
|
191
|
+
signal.notify();
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return reactiveProps;
|
|
197
|
+
}
|
package/dist/createContext.js
CHANGED
|
@@ -29,7 +29,7 @@ export function createContext() {
|
|
|
29
29
|
export function useContext(context) {
|
|
30
30
|
let currentComponent = getCurrentComponent();
|
|
31
31
|
if (!currentComponent) {
|
|
32
|
-
throw new Error("
|
|
32
|
+
throw new Error("Only use useContext in component setup");
|
|
33
33
|
}
|
|
34
34
|
if (typeof currentComponent.context.getContext !== "function") {
|
|
35
35
|
throw new Error("There is no parent context");
|
|
@@ -44,7 +44,7 @@ export function useInjectContext(context) {
|
|
|
44
44
|
return (value) => {
|
|
45
45
|
const currentComponent = getCurrentComponent();
|
|
46
46
|
if (!currentComponent) {
|
|
47
|
-
throw new Error("
|
|
47
|
+
throw new Error("Only use useInjectContext in component setup");
|
|
48
48
|
}
|
|
49
49
|
currentComponent.contexts.set(context, value);
|
|
50
50
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { ErrorBoundary } from "./error";
|
|
|
7
7
|
export { useRef } from "./useRef";
|
|
8
8
|
export { useView } from "./useView";
|
|
9
9
|
export { useEffect } from "./useEffect";
|
|
10
|
-
export {
|
|
10
|
+
export { useDerived, Derived } from "./useDerived";
|
|
11
11
|
export { syncBatch } from "./batch";
|
|
12
12
|
export { inspect } from "./inspect";
|
|
13
13
|
export { Router, useRouter } from "./useRouter";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EACL,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,cAAc,EACd,SAAS,GACV,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ export { ErrorBoundary } from "./error";
|
|
|
7
7
|
export { useRef } from "./useRef";
|
|
8
8
|
export { useView } from "./useView";
|
|
9
9
|
export { useEffect } from "./useEffect";
|
|
10
|
-
export {
|
|
10
|
+
export { useDerived } from "./useDerived";
|
|
11
11
|
export { syncBatch } from "./batch";
|
|
12
12
|
export { inspect } from "./inspect";
|
|
13
13
|
export { useRouter } from "./useRouter";
|