@xyo-network/react-shared 2.55.8 → 2.55.9

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,5 +1,5 @@
1
+ import { usePromise } from '@xylabs/react-promise';
1
2
  import { PayloadHasher } from '@xyo-network/core';
2
- import { usePromise } from './usePromise';
3
3
  export const usePayloadHash = (payload) => {
4
4
  return usePromise(() => (payload ? PayloadHasher.hashAsync(payload) : undefined), [payload])[0];
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"usePayloadHash.js","sourceRoot":"","sources":["../../../src/hooks/usePayloadHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,MAAM,CAAC,MAAM,cAAc,GAAG,CAA2B,OAAoC,EAAE,EAAE;IAC/F,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACjG,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAA2B,QAAuC,EAAE,EAAE;IACpG,OAAO,UAAU,CACf,GAAG,EAAE,CACH,QAAQ;QACN,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAA8B,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC9H,CAAC,CAAC,SAAS,EACf,CAAC,QAAQ,CAAC,CACX,CAAC,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
1
+ {"version":3,"file":"usePayloadHash.js","sourceRoot":"","sources":["../../../src/hooks/usePayloadHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,MAAM,CAAC,MAAM,cAAc,GAAG,CAA2B,OAAoC,EAAE,EAAE;IAC/F,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACjG,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAA2B,QAAuC,EAAE,EAAE;IACpG,OAAO,UAAU,CACf,GAAG,EAAE,CACH,QAAQ;QACN,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAA8B,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,MAAM,aAAa,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC9H,CAAC,CAAC,SAAS,EACf,CAAC,QAAQ,CAAC,CACX,CAAC,CAAC,CAAC,CAAA;AACN,CAAC,CAAA"}
@@ -1,62 +1,4 @@
1
- // Inspired from https://github.com/bsonntag/react-use-promise
2
- import { useEffect, useMemo, useState } from 'react';
3
- export var State;
4
- (function (State) {
5
- State["pending"] = "pending";
6
- State["rejected"] = "rejected";
7
- State["resolved"] = "resolved";
8
- })(State || (State = {}));
9
- /**
10
- * usePromise -
11
- */
12
- export const usePromise = (promise, dependencies, debug = undefined) => {
13
- const [result, setResult] = useState();
14
- const [error, setError] = useState();
15
- const [state, setState] = useState(State.pending);
16
- if (debug)
17
- console.log(`usePromise [${debug}]: started [${typeof promise}]`);
18
- const promiseMemo = useMemo(() => {
19
- try {
20
- if (debug)
21
- console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`);
22
- setState(State.pending);
23
- return promise?.();
24
- }
25
- catch (e) {
26
- if (debug)
27
- console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`);
28
- setResult(undefined);
29
- setError(e);
30
- setState(State.rejected);
31
- }
32
- }, dependencies);
33
- if (debug)
34
- console.log(`usePromise [${debug}] Main Function`);
35
- useEffect(() => {
36
- if (debug)
37
- console.log(`usePromise [${debug}] useEffect`);
38
- promiseMemo
39
- ?.then((payload) => {
40
- if (debug)
41
- console.log(`usePromise [${debug}] then`);
42
- setResult(payload);
43
- setError(undefined);
44
- setState(State.resolved);
45
- })
46
- .catch((e) => {
47
- const error = e;
48
- console.error(`usePromise: ${error.message}`);
49
- setResult(undefined);
50
- setError(error);
51
- setState(State.rejected);
52
- });
53
- return () => {
54
- if (debug)
55
- console.log(`usePromise [${debug}] useEffect callback`);
56
- };
57
- }, [...dependencies, promiseMemo]);
58
- if (debug)
59
- console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`);
60
- return [result, error, state];
61
- };
1
+ import { usePromise as importedUsePromise } from '@xylabs/react-promise';
2
+ /** @deprecated use @xylabs/react-promise version instead */
3
+ export const usePromise = importedUsePromise;
62
4
  //# sourceMappingURL=usePromise.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAE9D,OAAO,EAAkB,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEpE,MAAM,CAAN,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,4BAAmB,CAAA;IACnB,8BAAqB,CAAA;IACrB,8BAAqB,CAAA;AACvB,CAAC,EAJW,KAAK,KAAL,KAAK,QAIhB;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAA2C,EAC3C,YAA4B,EAC5B,QAA4B,SAAS,EACwB,EAAE;IAC/D,MAAM,CAAC,MAAM,EAAE,SAA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AAA;YACnB,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC1B,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACX,MAAM,KAAK,GAAG,CAAU,CAAA;YACxB,OAAO,CAAC,KAAK,CAAC,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;YAC7C,SAAS,CAAC,SAAS,CAAC,CAAA;YACpB,QAAQ,CAAC,KAAK,CAAC,CAAA;YACf,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;QACJ,OAAO,GAAG,EAAE;YACV,IAAI,KAAK;gBAAE,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,sBAAsB,CAAC,CAAA;QACpE,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,WAAW,CAAC,CAAC,CAAA;IAClC,IAAI,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,eAAe,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAA;IAC5G,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA"}
1
+ {"version":3,"file":"usePromise.js","sourceRoot":"","sources":["../../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAExE,4DAA4D;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,kBAAkB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"usePayloadHash.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePayloadHash.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc;;8DAE1B,CAAA;AAED,eAAO,MAAM,gBAAgB;;+EAQ5B,CAAA"}
1
+ {"version":3,"file":"usePayloadHash.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePayloadHash.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;8DAE1B,CAAA;AAED,eAAO,MAAM,gBAAgB;;+EAQ5B,CAAA"}
@@ -1,11 +1,4 @@
1
- import { DependencyList } from 'react';
2
- export declare enum State {
3
- pending = "pending",
4
- rejected = "rejected",
5
- resolved = "resolved"
6
- }
7
- /**
8
- * usePromise -
9
- */
10
- export declare const usePromise: <TResult>(promise: () => Promise<TResult> | undefined, dependencies: DependencyList, debug?: string | undefined) => [TResult | undefined, Error | undefined, State | undefined];
1
+ /// <reference types="react" />
2
+ /** @deprecated use @xylabs/react-promise version instead */
3
+ export declare const usePromise: <TResult>(promise: () => Promise<TResult> | undefined, dependencies: import("react").DependencyList, debug?: string | undefined) => [TResult | undefined, Error | undefined, import("@xylabs/react-promise").State | undefined];
11
4
  //# sourceMappingURL=usePromise.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePromise.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAgC,MAAM,OAAO,CAAA;AAEpE,oBAAY,KAAK;IACf,OAAO,YAAY;IACnB,QAAQ,aAAa;IACrB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,+FAGd,MAAM,GAAG,SAAS,gEA6C1B,CAAA"}
1
+ {"version":3,"file":"usePromise.d.ts","sourceRoot":"","sources":["../../../src/hooks/usePromise.ts"],"names":[],"mappings":";AAEA,4DAA4D;AAC5D,eAAO,MAAM,UAAU,iOAAqB,CAAA"}
package/package.json CHANGED
@@ -11,18 +11,19 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "@xylabs/pixel": "^1.4.13",
14
- "@xylabs/react-appbar": "^2.17.4",
15
- "@xylabs/react-button": "^2.17.4",
16
- "@xylabs/react-flexbox": "^2.17.4",
17
- "@xylabs/react-link": "^2.17.4",
18
- "@xylabs/react-shared": "^2.17.4",
14
+ "@xylabs/react-appbar": "^2.17.5",
15
+ "@xylabs/react-button": "^2.17.5",
16
+ "@xylabs/react-flexbox": "^2.17.5",
17
+ "@xylabs/react-link": "^2.17.5",
18
+ "@xylabs/react-promise": "^2.17.5",
19
+ "@xylabs/react-shared": "^2.17.5",
19
20
  "@xyo-network/core": "^2.63.6",
20
- "@xyo-network/payload-model": "^2.63.6",
21
- "@xyo-network/react-event": "^2.55.8"
21
+ "@xyo-network/payload-model": "^2.63.7",
22
+ "@xyo-network/react-event": "^2.55.9"
22
23
  },
23
24
  "devDependencies": {
24
25
  "@storybook/react": "^7.0.23",
25
- "@xylabs/react-quick-tip-button": "^2.17.4",
26
+ "@xylabs/react-quick-tip-button": "^2.17.5",
26
27
  "@xylabs/ts-scripts-yarn3": "^2.17.17",
27
28
  "@xylabs/tsconfig-react": "^2.17.17",
28
29
  "typescript": "^5.1.3"
@@ -79,5 +80,5 @@
79
80
  },
80
81
  "sideEffects": false,
81
82
  "types": "dist/types/index.d.ts",
82
- "version": "2.55.8"
83
+ "version": "2.55.9"
83
84
  }
@@ -1,8 +1,7 @@
1
+ import { usePromise } from '@xylabs/react-promise'
1
2
  import { PayloadHasher } from '@xyo-network/core'
2
3
  import { Payload } from '@xyo-network/payload-model'
3
4
 
4
- import { usePromise } from './usePromise'
5
-
6
5
  export const usePayloadHash = <TPayload extends Payload>(payload: TPayload | undefined | null) => {
7
6
  return usePromise(() => (payload ? PayloadHasher.hashAsync(payload) : undefined), [payload])[0]
8
7
  }
@@ -1,62 +1,4 @@
1
- // Inspired from https://github.com/bsonntag/react-use-promise
1
+ import { usePromise as importedUsePromise } from '@xylabs/react-promise'
2
2
 
3
- import { DependencyList, useEffect, useMemo, useState } from 'react'
4
-
5
- export enum State {
6
- pending = 'pending',
7
- rejected = 'rejected',
8
- resolved = 'resolved',
9
- }
10
-
11
- /**
12
- * usePromise -
13
- */
14
- export const usePromise = <TResult>(
15
- promise: () => Promise<TResult> | undefined,
16
- dependencies: DependencyList,
17
- debug: string | undefined = undefined,
18
- ): [TResult | undefined, Error | undefined, State | undefined] => {
19
- const [result, setResult] = useState<TResult>()
20
- const [error, setError] = useState<Error>()
21
- const [state, setState] = useState<State>(State.pending)
22
-
23
- if (debug) console.log(`usePromise [${debug}]: started [${typeof promise}]`)
24
-
25
- const promiseMemo = useMemo(() => {
26
- try {
27
- if (debug) console.log(`usePromise [${debug}]: re-memo [${typeof promise}]`)
28
- setState(State.pending)
29
- return promise?.()
30
- } catch (e) {
31
- if (debug) console.log(`usePromise [${debug}]: useMemo rejection [${typeof promise}]`)
32
- setResult(undefined)
33
- setError(e as Error)
34
- setState(State.rejected)
35
- }
36
- }, dependencies)
37
-
38
- if (debug) console.log(`usePromise [${debug}] Main Function`)
39
-
40
- useEffect(() => {
41
- if (debug) console.log(`usePromise [${debug}] useEffect`)
42
- promiseMemo
43
- ?.then((payload) => {
44
- if (debug) console.log(`usePromise [${debug}] then`)
45
- setResult(payload)
46
- setError(undefined)
47
- setState(State.resolved)
48
- })
49
- .catch((e) => {
50
- const error = e as Error
51
- console.error(`usePromise: ${error.message}`)
52
- setResult(undefined)
53
- setError(error)
54
- setState(State.rejected)
55
- })
56
- return () => {
57
- if (debug) console.log(`usePromise [${debug}] useEffect callback`)
58
- }
59
- }, [...dependencies, promiseMemo])
60
- if (debug) console.log(`usePromise [${debug}] returning ${JSON.stringify([result, error, state], null, 2)}`)
61
- return [result, error, state]
62
- }
3
+ /** @deprecated use @xylabs/react-promise version instead */
4
+ export const usePromise = importedUsePromise