applesauce-react 0.0.0-next-20251209200210 → 0.0.0-next-20251231055351
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/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +2 -1
- package/dist/hooks/use-$.d.ts +5 -0
- package/dist/hooks/use-$.js +7 -0
- package/dist/hooks/use-action-runner.d.ts +1 -0
- package/dist/hooks/{use-action-hub.js → use-action-runner.js} +1 -1
- package/dist/hooks/use-action.d.ts +2 -2
- package/dist/hooks/use-action.js +2 -2
- package/dist/providers/actions-provider.d.ts +5 -5
- package/dist/providers/actions-provider.js +3 -3
- package/package.json +5 -5
- package/dist/hooks/use-action-hub.d.ts +0 -1
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./use-account-manager.js";
|
|
2
2
|
export * from "./use-accounts.js";
|
|
3
|
-
export * from "./use-action-
|
|
3
|
+
export * from "./use-action-runner.js";
|
|
4
4
|
export * from "./use-action.js";
|
|
5
5
|
export * from "./use-active-account.js";
|
|
6
6
|
export * from "./use-event-factory.js";
|
|
@@ -10,3 +10,4 @@ export * from "./use-observable-memo.js";
|
|
|
10
10
|
export * from "./use-observable.js";
|
|
11
11
|
export * from "./use-render-nast.js";
|
|
12
12
|
export * from "./use-rendered-content.js";
|
|
13
|
+
export * from "./use-$.js";
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./use-account-manager.js";
|
|
2
2
|
export * from "./use-accounts.js";
|
|
3
|
-
export * from "./use-action-
|
|
3
|
+
export * from "./use-action-runner.js";
|
|
4
4
|
export * from "./use-action.js";
|
|
5
5
|
export * from "./use-active-account.js";
|
|
6
6
|
export * from "./use-event-factory.js";
|
|
@@ -10,3 +10,4 @@ export * from "./use-observable-memo.js";
|
|
|
10
10
|
export * from "./use-observable.js";
|
|
11
11
|
export * from "./use-render-nast.js";
|
|
12
12
|
export * from "./use-rendered-content.js";
|
|
13
|
+
export * from "./use-$.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
2
|
+
/** A utility hook that combines {@link useObservableState} and useMemo */
|
|
3
|
+
export declare function use$<T>(observable?: BehaviorSubject<T>): T;
|
|
4
|
+
export declare function use$<T>(observable?: Observable<T>): T | undefined;
|
|
5
|
+
export declare function use$<T>(factory: () => Observable<T> | undefined, deps: any[]): T | undefined;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { of } from "rxjs";
|
|
3
|
+
import { useObservableState } from "./use-observable-state.js";
|
|
4
|
+
export function use$(observable, deps) {
|
|
5
|
+
const resolved = useMemo(() => (typeof observable === "function" ? observable() : observable) ?? of(undefined), deps ?? [observable]);
|
|
6
|
+
return useObservableState(resolved);
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useActionRunner(): import("applesauce-actions").ActionRunner;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { ActionsContext } from "../providers/actions-provider.js";
|
|
3
|
-
export function
|
|
3
|
+
export function useActionRunner() {
|
|
4
4
|
const hub = useContext(ActionsContext);
|
|
5
5
|
if (!hub)
|
|
6
6
|
throw new Error("Missing ActionsProvider");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function useAction<Args extends Array<any>>(Action:
|
|
1
|
+
import { ActionBuilder } from "applesauce-actions";
|
|
2
|
+
export declare function useAction<Args extends Array<any>>(Action: ActionBuilder<Args>, args: Args | undefined): {
|
|
3
3
|
loading: boolean;
|
|
4
4
|
run: () => Promise<void>;
|
|
5
5
|
exec: () => import("rxjs").Observable<import("nostr-tools").Event> | undefined;
|
package/dist/hooks/use-action.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useCallback, useRef, useState } from "react";
|
|
2
2
|
import { finalize } from "rxjs";
|
|
3
|
-
import {
|
|
3
|
+
import { useActionRunner } from "./use-action-runner.js";
|
|
4
4
|
export function useAction(Action, args) {
|
|
5
5
|
const [loading, setLoading] = useState(false);
|
|
6
6
|
const ref = useRef(args);
|
|
7
7
|
ref.current = args;
|
|
8
|
-
const hub =
|
|
8
|
+
const hub = useActionRunner();
|
|
9
9
|
const run = useCallback(async () => {
|
|
10
10
|
if (args === undefined)
|
|
11
11
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
3
|
-
export declare const ActionsContext: import("react").Context<
|
|
4
|
-
/** Provides an
|
|
5
|
-
export declare function ActionsProvider({
|
|
6
|
-
|
|
2
|
+
import { ActionRunner } from "applesauce-actions";
|
|
3
|
+
export declare const ActionsContext: import("react").Context<ActionRunner | undefined>;
|
|
4
|
+
/** Provides an ActionRunner to the component tree */
|
|
5
|
+
export declare function ActionsProvider({ runner, children }: PropsWithChildren<{
|
|
6
|
+
runner?: ActionRunner;
|
|
7
7
|
}>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext } from "react";
|
|
3
3
|
export const ActionsContext = createContext(undefined);
|
|
4
|
-
/** Provides an
|
|
5
|
-
export function ActionsProvider({
|
|
6
|
-
return _jsx(ActionsContext.Provider, { value:
|
|
4
|
+
/** Provides an ActionRunner to the component tree */
|
|
5
|
+
export function ActionsProvider({ runner, children }) {
|
|
6
|
+
return _jsx(ActionsContext.Provider, { value: runner, children: children });
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "applesauce-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20251231055351",
|
|
4
4
|
"description": "React hooks for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"applesauce-accounts": "0.0.0-next-
|
|
52
|
-
"applesauce-actions": "0.0.0-next-
|
|
53
|
-
"applesauce-content": "0.0.0-next-
|
|
54
|
-
"applesauce-core": "0.0.0-next-
|
|
51
|
+
"applesauce-accounts": "0.0.0-next-20251231055351",
|
|
52
|
+
"applesauce-actions": "0.0.0-next-20251231055351",
|
|
53
|
+
"applesauce-content": "0.0.0-next-20251231055351",
|
|
54
|
+
"applesauce-core": "0.0.0-next-20251231055351",
|
|
55
55
|
"hash-sum": "^2.0.0",
|
|
56
56
|
"observable-hooks": "^4.2.4",
|
|
57
57
|
"react": "^18.3.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useActionHub(): import("applesauce-actions").ActionHub;
|