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 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
- - **`useComputed`** - Derive values from state with automatic caching
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 createMountEffect in component setup");
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 createCleanup in component setup");
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 (!self.isRendering && observer) {
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) {
@@ -22,11 +22,12 @@
22
22
  *
23
23
  * @returns Context object with inject() and get() methods
24
24
  */
25
- export type Context<T> = {
26
- inject(value: T): void;
27
- get(): T;
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,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI;IACvB,MAAM,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IACvB,GAAG,IAAI,CAAC,CAAC;CACV,CAAC;AAEF,wBAAgB,aAAa,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAqC7C;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;AACnE,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC"}
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"}
@@ -24,35 +24,28 @@
24
24
  */
25
25
  import { getCurrentComponent } from "./component";
26
26
  export function createContext() {
27
- const context = {
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, value) {
53
- if (value) {
54
- context.inject(value);
55
- return;
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 context.get();
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 { createRef as useRef } from "inferno";
7
+ export { useRef } from "./useRef";
8
8
  export { useView } from "./useView";
9
9
  export { useEffect } from "./useEffect";
10
- export { useComputed } from "./useComputed";
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";
@@ -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;AAC5D,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,SAAS,IAAI,MAAM,EAAE,MAAM,SAAS,CAAC;AAC9C,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"}
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 { createRef as useRef } from "inferno";
7
+ export { useRef } from "./useRef";
8
8
  export { useView } from "./useView";
9
9
  export { useEffect } from "./useEffect";
10
- export { useComputed } from "./useComputed";
10
+ export { useDerived } from "./useDerived";
11
11
  export { syncBatch } from "./batch";
12
12
  export { inspect } from "./inspect";
13
13
  export { useRouter } from "./useRouter";