rask-ui 0.19.0 → 0.20.1

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.
@@ -1,11 +1,12 @@
1
1
  import { VNode, Component, Props, InfernoNode } from "inferno";
2
- import { Observer } from "./observation";
2
+ import { Observer, Signal } 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
6
  private isNotified;
7
7
  private isReconciling;
8
8
  observer: Observer;
9
+ propsSignals: Record<string, Signal>;
9
10
  private reactiveProps;
10
11
  shouldComponentUpdate(): boolean;
11
12
  componentWillMount(): void;
@@ -19,7 +20,8 @@ export type RaskStatefulFunctionComponent<P extends Props<any>> = (() => () => V
19
20
  export declare class RaskStatefulComponent<P extends Props<any>> extends Component<P> {
20
21
  setup: RaskStatefulFunctionComponent<P>;
21
22
  private renderFn?;
22
- private reactiveProps?;
23
+ propsSignals: Record<string, Signal>;
24
+ private reactiveProps;
23
25
  private isNotified;
24
26
  private isReconciling;
25
27
  observer: Observer;
@@ -1 +1 @@
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,CAA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AAK,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,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IAC1C,OAAO,CAAC,aAAa,CAAc;IAwBnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAS;IAE9B,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;CA6CP;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,SAO9D"}
package/dist/component.js CHANGED
@@ -12,6 +12,7 @@ export class RaskStatelessComponent extends Component {
12
12
  }
13
13
  this.forceUpdate();
14
14
  });
15
+ propsSignals = {};
15
16
  reactiveProps;
16
17
  shouldComponentUpdate() {
17
18
  const shouldRender = this.isNotified;
@@ -24,16 +25,17 @@ export class RaskStatelessComponent extends Component {
24
25
  }
25
26
  componentWillReceiveProps(nextProps) {
26
27
  this.isReconciling = true;
28
+ const prevProps = this.props;
29
+ this.props = nextProps;
27
30
  syncBatch(() => {
28
- for (const prop in nextProps) {
29
- if (this.props[prop] === nextProps[prop]) {
31
+ for (const prop in this.propsSignals) {
32
+ if (prevProps[prop] === nextProps[prop]) {
30
33
  continue;
31
34
  }
32
- // @ts-ignore
33
- this.reactiveProps[prop] = nextProps[prop];
35
+ // This just triggers the signal
36
+ this.propsSignals[prop].notify();
34
37
  }
35
38
  });
36
- this.props = nextProps;
37
39
  }
38
40
  render() {
39
41
  const stopObserving = this.observer.observe();
@@ -60,6 +62,7 @@ export function useCleanup(cb) {
60
62
  }
61
63
  export class RaskStatefulComponent extends Component {
62
64
  renderFn;
65
+ propsSignals = {};
63
66
  reactiveProps;
64
67
  // RECONCILIATION FLAGS
65
68
  // --------------------
@@ -115,16 +118,16 @@ export class RaskStatefulComponent extends Component {
115
118
  }
116
119
  componentWillReceiveProps(nextProps) {
117
120
  this.isReconciling = true;
121
+ const prevProps = this.props;
122
+ this.props = nextProps;
118
123
  syncBatch(() => {
119
- for (const prop in nextProps) {
120
- if (this.props[prop] === nextProps[prop]) {
124
+ for (const prop in this.propsSignals) {
125
+ if (prevProps[prop] === nextProps[prop]) {
121
126
  continue;
122
127
  }
123
- // @ts-ignore
124
- this.reactiveProps[prop] = nextProps[prop];
128
+ this.propsSignals[prop].notify();
125
129
  }
126
130
  });
127
- this.props = nextProps;
128
131
  }
129
132
  shouldComponentUpdate() {
130
133
  const shouldRender = this.isNotified;
@@ -176,40 +179,24 @@ export function createComponent(props, key) {
176
179
  return createComponentVNode(4 /* VNodeFlags.ComponentClass */, RaskStatefulComponent, props, key);
177
180
  }
178
181
  function createReactiveProps(comp) {
179
- const reactiveProps = {};
180
- const signals = new Map();
181
- for (const prop in comp.props) {
182
- const value = comp.props[prop];
183
- // Skip known non-reactive props
184
- if (prop === "key" || prop === "ref") {
185
- reactiveProps[prop] = value;
186
- continue;
187
- }
188
- // Only create reactive getters for primitives
189
- Object.defineProperty(reactiveProps, prop, {
190
- enumerable: true,
191
- get() {
192
- const observer = getCurrentObserver();
193
- if (observer) {
194
- // Lazy create signal only when accessed in reactive context
195
- let signal = signals.get(prop);
196
- if (!signal) {
197
- signal = new Signal();
198
- signals.set(prop, signal);
199
- }
200
- observer.subscribeSignal(signal);
201
- }
202
- return comp.props[prop];
203
- },
204
- set(value) {
205
- comp.props[prop] = value;
206
- // Only notify if signal was created (i.e., prop was accessed reactively)
207
- const signal = signals.get(prop);
208
- if (signal) {
209
- signal.notify();
182
+ const props = new Proxy({}, {
183
+ get(_, prop) {
184
+ // Skip known non-reactive props
185
+ if (prop === "key" || prop === "ref") {
186
+ return;
187
+ }
188
+ const observer = getCurrentObserver();
189
+ if (observer) {
190
+ // Lazy create signal only when accessed in reactive context
191
+ let signal = comp.propsSignals[prop];
192
+ if (!signal) {
193
+ signal = new Signal();
194
+ comp.propsSignals[prop] = signal;
210
195
  }
211
- },
212
- });
213
- }
214
- return reactiveProps;
196
+ observer.subscribeSignal(signal);
197
+ }
198
+ return comp.props[prop];
199
+ },
200
+ });
201
+ return props;
215
202
  }
@@ -1,18 +1,29 @@
1
- export type QueuedAction<P> = {
1
+ export type ActionState<T, P> = {
2
+ isPending: false;
3
+ params: null;
4
+ result: null;
5
+ error: null;
6
+ } | {
7
+ isPending: true;
2
8
  params: P;
3
- error: Error | null;
4
- retry(): void;
5
- cancel(): void;
6
- };
7
- export type ActionState<P> = {
8
- isPending: boolean;
9
- queue: QueuedAction<P>[];
9
+ result: null;
10
+ error: null;
11
+ } | {
12
+ isPending: false;
13
+ params: P;
14
+ result: T;
15
+ error: null;
16
+ } | {
17
+ isPending: false;
18
+ params: P;
19
+ result: null;
20
+ error: Error;
10
21
  };
11
- export type Action<P = null> = [
12
- ActionState<P>,
22
+ export type Action<T, P = null> = [
23
+ ActionState<T, P>,
13
24
  [
14
25
  P
15
26
  ] extends [null] ? () => void : (params: P) => void
16
27
  ];
17
- export declare function useAction<P = null>(fn: [P] extends [null] ? () => Promise<void> : (params: P) => Promise<void>): Action<P>;
28
+ export declare function useAction<T, P = null>(fn: [P] extends [null] ? () => Promise<T> : (params: P) => Promise<T>): Action<T, P>;
18
29
  //# sourceMappingURL=useAction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAction.d.ts","sourceRoot":"","sources":["../src/useAction.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAC5B,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,KAAK,IAAI,IAAI,CAAC;IACd,MAAM,IAAI,IAAI,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,IAAI,IAAI;IAC7B,WAAW,CAAC,CAAC,CAAC;IACd;QAAC,CAAC;KAAC,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI;CACtD,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,GAAG,IAAI,EAChC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAC1E,MAAM,CAAC,CAAC,CAAC,CAkDX"}
1
+ {"version":3,"file":"useAction.d.ts","sourceRoot":"","sources":["../src/useAction.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IACxB;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,IAAI,CAAC;IACb,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,CAAC,CAAC;IACV,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,CAAC,CAAC;IACV,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IACE,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,EAAE,CAAC,CAAC;IACV,MAAM,EAAE,IAAI,CAAC;IACb,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEN,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,IAAI;IAChC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IACjB;QAAC,CAAC;KAAC,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI;CACtD,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,EACnC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GACpE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAkDd"}
package/dist/useAction.js CHANGED
@@ -1,43 +1,45 @@
1
- import { useState } from "./useState";
1
+ import { assignState, useState } from "./useState";
2
2
  export function useAction(fn) {
3
3
  const state = useState({
4
4
  isPending: false,
5
- queue: [],
5
+ error: null,
6
+ params: null,
7
+ result: null,
6
8
  });
7
- const processQueue = () => {
8
- const next = state.queue[0];
9
- if (!next) {
10
- state.isPending = false;
11
- return;
12
- }
13
- state.isPending = true;
14
- fn(next.params)
15
- .then(() => {
16
- state.queue.shift();
17
- processQueue();
18
- })
19
- .catch((error) => {
20
- next.error = error;
21
- });
22
- };
9
+ let abortController;
23
10
  const run = (params) => {
24
11
  params = (params || null);
25
- let actionProxy;
26
- const index = state.queue.push({
27
- params,
12
+ abortController?.abort();
13
+ const currentAbortController = (abortController = new AbortController());
14
+ assignState(state, {
15
+ isPending: true,
28
16
  error: null,
29
- retry() {
30
- processQueue();
31
- },
32
- cancel() {
33
- state.queue.splice(state.queue.indexOf(actionProxy), 1);
34
- processQueue();
35
- },
36
- }) - 1;
37
- actionProxy = state.queue[index];
38
- if (index === 0) {
39
- processQueue();
40
- }
17
+ params,
18
+ result: null,
19
+ });
20
+ fn(params)
21
+ .then((result) => {
22
+ if (currentAbortController.signal.aborted) {
23
+ return;
24
+ }
25
+ assignState(state, {
26
+ isPending: false,
27
+ error: null,
28
+ params,
29
+ result,
30
+ });
31
+ })
32
+ .catch((error) => {
33
+ if (currentAbortController.signal.aborted) {
34
+ return;
35
+ }
36
+ assignState(state, {
37
+ isPending: false,
38
+ error,
39
+ params,
40
+ result: null,
41
+ });
42
+ });
41
43
  };
42
44
  return [state, run];
43
45
  }
@@ -1,40 +1,35 @@
1
1
  import { AsyncState } from "./useAsync";
2
- type SuspendState<T extends Record<string, () => any>> = {
2
+ type SuspendState<T extends Record<string, () => any>> = ({
3
3
  error: Error;
4
4
  isLoading: true;
5
5
  isRefreshing: false;
6
- values: {
7
- [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? ReturnType<T[K]>["value"] : ReturnType<T[K]>;
8
- };
9
- } | {
6
+ } & {
7
+ [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? ReturnType<T[K]>["value"] : ReturnType<T[K]>;
8
+ }) | ({
10
9
  error: Error;
11
10
  isLoading: false;
12
11
  isRefreshing: true;
13
- values: {
14
- [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? NonNullable<ReturnType<T[K]>["value"]> : ReturnType<T[K]>;
15
- };
16
- } | {
12
+ } & {
13
+ [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? NonNullable<ReturnType<T[K]>["value"]> : ReturnType<T[K]>;
14
+ }) | ({
17
15
  error: null;
18
16
  isLoading: true;
19
17
  isRefreshing: false;
20
- values: {
21
- [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? ReturnType<T[K]>["value"] : ReturnType<T[K]>;
22
- };
23
- } | {
18
+ } & {
19
+ [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? ReturnType<T[K]>["value"] : ReturnType<T[K]>;
20
+ }) | ({
24
21
  error: null;
25
22
  isLoading: false;
26
23
  isRefreshing: true;
27
- values: {
28
- [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? NonNullable<ReturnType<T[K]>["value"]> : ReturnType<T[K]>;
29
- };
30
- } | {
24
+ } & {
25
+ [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? NonNullable<ReturnType<T[K]>["value"]> : ReturnType<T[K]>;
26
+ }) | ({
31
27
  error: null;
32
28
  isLoading: false;
33
29
  isRefreshing: false;
34
- values: {
35
- [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? NonNullable<ReturnType<T[K]>["value"]> : ReturnType<T[K]>;
36
- };
37
- };
30
+ } & {
31
+ [K in keyof T]: ReturnType<T[K]> extends AsyncState<any> ? NonNullable<ReturnType<T[K]>["value"]> : ReturnType<T[K]>;
32
+ });
38
33
  export declare function useSuspend<T extends Record<string, any>>(asyncs: T): SuspendState<T>;
39
34
  export {};
40
35
  //# sourceMappingURL=useSuspend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSuspend.d.ts","sourceRoot":"","sources":["../src/useSuspend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,YAAY,CAAC;AAIjD,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,IACjD;IACE,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,EAAE,KAAK,CAAC;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AAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GACtC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACrB,CAAC,CAAC;AAEP,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,mBA0DlE"}
@@ -2,19 +2,18 @@ import { isAsync } from "./useAsync";
2
2
  import { useEffect } from "./useEffect";
3
3
  import { assignState, useState } from "./useState";
4
4
  export function useSuspend(asyncs) {
5
- const state = useState({
5
+ const state = useState(Object.keys(asyncs).reduce((aggr, key) => {
6
+ let value = asyncs[key]();
7
+ if (isAsync(value)) {
8
+ value = value.value;
9
+ }
10
+ aggr[key] = value;
11
+ return aggr;
12
+ }, {
6
13
  isLoading: true,
7
14
  isRefreshing: false,
8
15
  error: null,
9
- values: Object.keys(asyncs).reduce((aggr, key) => {
10
- let value = asyncs[key]();
11
- if (isAsync(value)) {
12
- value = value.value;
13
- }
14
- aggr[key] = value;
15
- return aggr;
16
- }, {}),
17
- });
16
+ }));
18
17
  useEffect(() => {
19
18
  let isLoading = false;
20
19
  let isRefreshing = false;
@@ -41,7 +40,7 @@ export function useSuspend(asyncs) {
41
40
  state.isRefreshing = isLoading ? false : isRefreshing;
42
41
  state.error = error || null;
43
42
  if (!state.isLoading && !state.isRefreshing && !error) {
44
- assignState(state.values, values);
43
+ assignState(state, values);
45
44
  }
46
45
  });
47
46
  return state;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rask-ui",
3
- "version": "0.19.0",
3
+ "version": "0.20.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",