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/dist/useAsync.js CHANGED
@@ -3,7 +3,7 @@ import { assignState, useState } from "./useState";
3
3
  export function useAsync(...args) {
4
4
  const currentComponent = getCurrentComponent();
5
5
  if (!currentComponent || currentComponent.isRendering) {
6
- throw new Error("Only use createTask in component setup");
6
+ throw new Error("Only use useTask in component setup");
7
7
  }
8
8
  const value = args.length === 2 ? args[0] : null;
9
9
  const fn = args.length === 2 ? args[1] : args[0];
@@ -0,0 +1,5 @@
1
+ export type Derived<T extends Record<string, () => any>> = {
2
+ [K in keyof T]: ReturnType<T[K]>;
3
+ };
4
+ export declare function useDerived<T extends Record<string, () => any>>(computed: T): Derived<T>;
5
+ //# sourceMappingURL=useDerived.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDerived.d.ts","sourceRoot":"","sources":["../src/useDerived.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,IAAI;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAC5D,QAAQ,EAAE,CAAC,GACV,OAAO,CAAC,CAAC,CAAC,CAgFZ"}
@@ -0,0 +1,72 @@
1
+ import { getCurrentComponent, useCleanup } from "./component";
2
+ import { INSPECT_MARKER, INSPECTOR_ENABLED } from "./inspect";
3
+ import { getCurrentObserver, Observer, Signal } from "./observation";
4
+ export function useDerived(computed) {
5
+ const currentComponent = getCurrentComponent();
6
+ if (!currentComponent || currentComponent.isRendering) {
7
+ throw new Error("Only use useDerived in component setup");
8
+ }
9
+ const proxy = {};
10
+ let notifyInspectorRef = {};
11
+ for (const prop in computed) {
12
+ let isDirty = true;
13
+ let value;
14
+ const signal = new Signal();
15
+ const computedObserver = new Observer(() => {
16
+ isDirty = true;
17
+ signal.notify();
18
+ if (INSPECTOR_ENABLED) {
19
+ notifyInspectorRef.current?.notify({
20
+ type: "computed",
21
+ path: notifyInspectorRef.current.path.concat(prop),
22
+ isDirty: true,
23
+ value,
24
+ });
25
+ }
26
+ });
27
+ useCleanup(() => computedObserver.dispose());
28
+ Object.defineProperty(proxy, prop, {
29
+ enumerable: true,
30
+ configurable: true,
31
+ get() {
32
+ const currentObserver = getCurrentObserver();
33
+ if (currentObserver) {
34
+ currentObserver.subscribeSignal(signal);
35
+ }
36
+ if (isDirty) {
37
+ const stopObserving = computedObserver.observe();
38
+ value = computed[prop]();
39
+ stopObserving();
40
+ isDirty = false;
41
+ if (INSPECTOR_ENABLED) {
42
+ notifyInspectorRef.current?.notify({
43
+ type: "computed",
44
+ path: notifyInspectorRef.current.path.concat(prop),
45
+ isDirty: false,
46
+ value,
47
+ });
48
+ }
49
+ return value;
50
+ }
51
+ return value;
52
+ },
53
+ });
54
+ }
55
+ if (INSPECTOR_ENABLED) {
56
+ Object.defineProperty(proxy, INSPECT_MARKER, {
57
+ enumerable: false,
58
+ configurable: false,
59
+ get() {
60
+ return !notifyInspectorRef.current;
61
+ },
62
+ set: (value) => {
63
+ Object.defineProperty(notifyInspectorRef, "current", {
64
+ get() {
65
+ return value.current;
66
+ },
67
+ });
68
+ },
69
+ });
70
+ }
71
+ return proxy;
72
+ }
package/dist/useEffect.js CHANGED
@@ -4,7 +4,7 @@ import { Observer } from "./observation";
4
4
  export function useEffect(cb) {
5
5
  const component = getCurrentComponent();
6
6
  if (!component || component.isRendering) {
7
- throw new Error("Only use createEffect in component setup");
7
+ throw new Error("Only use useEffect in component setup");
8
8
  }
9
9
  let disposer;
10
10
  const observer = new Observer(() => {
@@ -0,0 +1,3 @@
1
+ import { RefObject } from "inferno";
2
+ export declare function useRef<T>(): RefObject<T>;
3
+ //# sourceMappingURL=useRef.d.ts.map
@@ -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;AAIpC,wBAAgB,MAAM,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAoBxC"}
package/dist/useRef.js ADDED
@@ -0,0 +1,21 @@
1
+ import { getCurrentObserver, Signal } from "./observation";
2
+ import { getCurrentComponent } from "./component";
3
+ export function useRef() {
4
+ let value = null;
5
+ const currentComponent = getCurrentComponent();
6
+ if (!currentComponent || currentComponent.isRendering) {
7
+ throw new Error("Only use useRef in component setup");
8
+ }
9
+ const signal = new Signal();
10
+ return {
11
+ get current() {
12
+ const currentObserver = getCurrentObserver();
13
+ currentObserver?.subscribeSignal(signal);
14
+ return value;
15
+ },
16
+ set current(newValue) {
17
+ signal.notify();
18
+ value = newValue;
19
+ },
20
+ };
21
+ }
package/dist/useRouter.js CHANGED
@@ -3,7 +3,7 @@ import { getCurrentObserver, Signal } from "./observation";
3
3
  import { useCleanup, getCurrentComponent } from "./component";
4
4
  export function useRouter(config, options) {
5
5
  if (!getCurrentComponent()) {
6
- throw new Error("Only use createRouter in component setup");
6
+ throw new Error("Only use useRouter in component setup");
7
7
  }
8
8
  const router = internalCreateRouter(config, options);
9
9
  const signal = new Signal();
@@ -9,14 +9,14 @@ export declare function assignState<T extends object>(state: T, newState: T): T;
9
9
  * @example
10
10
  * // ❌ Bad - destructuring loses reactivity
11
11
  * function Component(props) {
12
- * const state = createState({ count: 0, name: "foo" });
12
+ * const state = useState({ count: 0, name: "foo" });
13
13
  * const { count, name } = state; // Don't do this!
14
14
  * return () => <div>{count} {name}</div>; // Won't update!
15
15
  * }
16
16
  *
17
17
  * // ✅ Good - access properties directly in render
18
18
  * function Component(props) {
19
- * const state = createState({ count: 0, name: "foo" });
19
+ * const state = useState({ count: 0, name: "foo" });
20
20
  * return () => <div>{state.count} {state.name}</div>; // Reactive!
21
21
  * }
22
22
  *
package/dist/useState.js CHANGED
@@ -14,14 +14,14 @@ export function assignState(state, newState) {
14
14
  * @example
15
15
  * // ❌ Bad - destructuring loses reactivity
16
16
  * function Component(props) {
17
- * const state = createState({ count: 0, name: "foo" });
17
+ * const state = useState({ count: 0, name: "foo" });
18
18
  * const { count, name } = state; // Don't do this!
19
19
  * return () => <div>{count} {name}</div>; // Won't update!
20
20
  * }
21
21
  *
22
22
  * // ✅ Good - access properties directly in render
23
23
  * function Component(props) {
24
- * const state = createState({ count: 0, name: "foo" });
24
+ * const state = useState({ count: 0, name: "foo" });
25
25
  * return () => <div>{state.count} {state.name}</div>; // Reactive!
26
26
  * }
27
27
  *
@@ -30,7 +30,7 @@ export function assignState(state, newState) {
30
30
  */
31
31
  export function useState(state) {
32
32
  if (getCurrentComponent()?.isRendering) {
33
- throw new Error("createState cannot be called during render. Call it in component setup or globally.");
33
+ throw new Error("useState cannot be called during render. Call it in component setup or globally.");
34
34
  }
35
35
  return getProxy(state, {});
36
36
  }
package/dist/useView.js CHANGED
@@ -2,7 +2,7 @@ import { getCurrentComponent } from "./component";
2
2
  import { INSPECT_MARKER, INSPECTOR_ENABLED } from "./inspect";
3
3
  export function useView(...args) {
4
4
  if (!getCurrentComponent()) {
5
- throw new Error("Only use createView in component setup");
5
+ throw new Error("Only use useView in component setup");
6
6
  }
7
7
  const result = {};
8
8
  const seen = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.14.1",
3
+ "version": "0.17.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",