rask-ui 0.14.1 → 0.17.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/component.js +3 -3
- package/dist/createContext.d.ts +5 -4
- package/dist/createContext.d.ts.map +1 -1
- package/dist/createContext.js +22 -29
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- 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 +3 -0
- package/dist/useRef.d.ts.map +1 -0
- package/dist/useRef.js +21 -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/component.js
CHANGED
|
@@ -28,13 +28,13 @@ export function getCurrentComponent() {
|
|
|
28
28
|
}
|
|
29
29
|
export function useMountEffect(cb) {
|
|
30
30
|
if (!currentComponent) {
|
|
31
|
-
throw new Error("Only use
|
|
31
|
+
throw new Error("Only use useMountEffect in component setup");
|
|
32
32
|
}
|
|
33
33
|
currentComponent.onMounts.push(cb);
|
|
34
34
|
}
|
|
35
35
|
export function useCleanup(cb) {
|
|
36
36
|
if (!currentComponent || currentComponent.isRendering) {
|
|
37
|
-
throw new Error("Only use
|
|
37
|
+
throw new Error("Only use useCleanup in component setup");
|
|
38
38
|
}
|
|
39
39
|
currentComponent.onCleanups.push(cb);
|
|
40
40
|
}
|
|
@@ -91,7 +91,7 @@ export class RaskStatefulComponent extends Component {
|
|
|
91
91
|
enumerable: true,
|
|
92
92
|
get() {
|
|
93
93
|
const observer = getCurrentObserver();
|
|
94
|
-
if (
|
|
94
|
+
if (observer) {
|
|
95
95
|
// Lazy create signal only when accessed in reactive context
|
|
96
96
|
let signal = signals.get(prop);
|
|
97
97
|
if (!signal) {
|
package/dist/createContext.d.ts
CHANGED
|
@@ -22,11 +22,12 @@
|
|
|
22
22
|
*
|
|
23
23
|
* @returns Context object with inject() and get() methods
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
declare const Type: unique symbol;
|
|
26
|
+
export type Context<T> = symbol & {
|
|
27
|
+
readonly [Type]: T;
|
|
28
28
|
};
|
|
29
29
|
export declare function createContext<T>(): Context<T>;
|
|
30
|
-
export declare function useContext<T>(context: Context<T>, value: T): void;
|
|
31
30
|
export declare function useContext<T>(context: Context<T>): T;
|
|
31
|
+
export declare function useInjectContext<T>(context: Context<T>): (value: T) => void;
|
|
32
|
+
export {};
|
|
32
33
|
//# sourceMappingURL=createContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,
|
|
1
|
+
{"version":3,"file":"createContext.d.ts","sourceRoot":"","sources":["../src/createContext.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,CAAC,MAAM,IAAI,EAAE,OAAO,MAAM,CAAC;AAElC,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,MAAM,GAAG;IAChC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CACpB,CAAC;AAEF,wBAAgB,aAAa,CAAC,CAAC,KACV,OAAO,CAAC,CAAC,CAAC,CAC9B;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAkBpD;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAC7C,OAAO,CAAC,UASjB"}
|
package/dist/createContext.js
CHANGED
|
@@ -24,35 +24,28 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { getCurrentComponent } from "./component";
|
|
26
26
|
export function createContext() {
|
|
27
|
-
|
|
28
|
-
inject(value) {
|
|
29
|
-
const currentComponent = getCurrentComponent();
|
|
30
|
-
if (!currentComponent) {
|
|
31
|
-
throw new Error("You can not inject context outside component setup");
|
|
32
|
-
}
|
|
33
|
-
currentComponent.contexts.set(context, value);
|
|
34
|
-
},
|
|
35
|
-
get() {
|
|
36
|
-
let currentComponent = getCurrentComponent();
|
|
37
|
-
if (!currentComponent) {
|
|
38
|
-
throw new Error("You can not get context outside component setup");
|
|
39
|
-
}
|
|
40
|
-
if (typeof currentComponent.context.getContext !== "function") {
|
|
41
|
-
throw new Error("There is no parent context");
|
|
42
|
-
}
|
|
43
|
-
const contextValue = currentComponent.context.getContext(context);
|
|
44
|
-
if (!contextValue) {
|
|
45
|
-
throw new Error("There is a parent context, but not the one you are using");
|
|
46
|
-
}
|
|
47
|
-
return contextValue;
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
return context;
|
|
27
|
+
return Symbol();
|
|
51
28
|
}
|
|
52
|
-
export function useContext(context
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
29
|
+
export function useContext(context) {
|
|
30
|
+
let currentComponent = getCurrentComponent();
|
|
31
|
+
if (!currentComponent) {
|
|
32
|
+
throw new Error("Only use useContext in component setup");
|
|
33
|
+
}
|
|
34
|
+
if (typeof currentComponent.context.getContext !== "function") {
|
|
35
|
+
throw new Error("There is no parent context");
|
|
36
|
+
}
|
|
37
|
+
const contextValue = currentComponent.context.getContext(context);
|
|
38
|
+
if (!contextValue) {
|
|
39
|
+
throw new Error("There is a parent context, but not the one you are using");
|
|
56
40
|
}
|
|
57
|
-
return
|
|
41
|
+
return contextValue;
|
|
42
|
+
}
|
|
43
|
+
export function useInjectContext(context) {
|
|
44
|
+
return (value) => {
|
|
45
|
+
const currentComponent = getCurrentComponent();
|
|
46
|
+
if (!currentComponent) {
|
|
47
|
+
throw new Error("Only use useInjectContext in component setup");
|
|
48
|
+
}
|
|
49
|
+
currentComponent.contexts.set(context, value);
|
|
50
|
+
};
|
|
58
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { render } from "./render";
|
|
2
2
|
export { useCleanup, useMountEffect, RaskStatefulComponent, RaskStatelessComponent, } from "./component";
|
|
3
|
-
export { createContext, useContext } from "./createContext";
|
|
3
|
+
export { createContext, useContext, useInjectContext } from "./createContext";
|
|
4
4
|
export { useState, assignState } from "./useState";
|
|
5
5
|
export { useAsync, Async } from "./useAsync";
|
|
6
6
|
export { ErrorBoundary } from "./error";
|
|
7
|
-
export {
|
|
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,MAAM,iBAAiB,CAAC;
|
|
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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { render } from "./render";
|
|
2
2
|
export { useCleanup, useMountEffect, RaskStatefulComponent, RaskStatelessComponent, } from "./component";
|
|
3
|
-
export { createContext, useContext } from "./createContext";
|
|
3
|
+
export { createContext, useContext, useInjectContext } from "./createContext";
|
|
4
4
|
export { useState, assignState } from "./useState";
|
|
5
5
|
export { useAsync } from "./useAsync";
|
|
6
6
|
export { ErrorBoundary } from "./error";
|
|
7
|
-
export {
|
|
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";
|