rask-ui 0.14.1 → 0.16.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/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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/useRef.d.ts +3 -0
- package/dist/useRef.d.ts.map +1 -0
- package/dist/useRef.js +16 -0
- package/package.json +1 -1
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("You can not get context outside 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("You can not inject context outside component setup");
|
|
48
|
+
}
|
|
49
|
+
currentComponent.contexts.set(context, value);
|
|
50
|
+
};
|
|
58
51
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
10
|
export { useComputed } from "./useComputed";
|
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,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,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,10 +1,10 @@
|
|
|
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
10
|
export { useComputed } from "./useComputed";
|
package/dist/useRef.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRef.d.ts","sourceRoot":"","sources":["../src/useRef.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,wBAAgB,MAAM,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAcxC"}
|
package/dist/useRef.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getCurrentObserver, Signal } from "./observation";
|
|
2
|
+
export function useRef() {
|
|
3
|
+
let value = null;
|
|
4
|
+
const signal = new Signal();
|
|
5
|
+
return {
|
|
6
|
+
get current() {
|
|
7
|
+
const currentObserver = getCurrentObserver();
|
|
8
|
+
currentObserver?.subscribeSignal(signal);
|
|
9
|
+
return value;
|
|
10
|
+
},
|
|
11
|
+
set current(newValue) {
|
|
12
|
+
signal.notify();
|
|
13
|
+
value = newValue;
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|