applesauce-react 0.0.0-next-20250522030625 → 0.0.0-next-20250606170247
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/__tests__/exports.test.js +0 -2
- package/dist/hooks/__tests__/exports.test.js +22 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +2 -2
- package/dist/hooks/use-event-model.d.ts +3 -0
- package/dist/hooks/use-event-model.js +16 -0
- package/dist/hooks/use-observable-memo.d.ts +7 -0
- package/dist/hooks/use-observable-memo.js +9 -0
- package/dist/hooks/use-observable.d.ts +1 -4
- package/dist/hooks/use-observable.js +2 -5
- package/dist/hooks/use-query-store.d.ts +1 -1
- package/dist/providers/__tests__/exports.test.js +0 -2
- package/dist/providers/store-provider.d.ts +1 -6
- package/dist/providers/store-provider.js +0 -5
- package/package.json +6 -6
- package/dist/hooks/use-active-accounts.d.ts +0 -1
- package/dist/hooks/use-active-accounts.js +0 -6
- package/dist/provider.d.ts +0 -7
- package/dist/provider.js +0 -7
- package/dist/providers/query-store-provider.d.ts +0 -7
- package/dist/providers/query-store-provider.js +0 -7
|
@@ -5,18 +5,38 @@ describe("exports", () => {
|
|
|
5
5
|
expect(Object.keys(exports).sort()).toMatchInlineSnapshot(`
|
|
6
6
|
[
|
|
7
7
|
"ComponentMap",
|
|
8
|
+
"ObservableResource",
|
|
9
|
+
"identity",
|
|
10
|
+
"pluckCurrentTargetChecked",
|
|
11
|
+
"pluckCurrentTargetValue",
|
|
12
|
+
"pluckFirst",
|
|
8
13
|
"useAccountManager",
|
|
9
14
|
"useAccounts",
|
|
10
15
|
"useAction",
|
|
11
16
|
"useActionHub",
|
|
12
17
|
"useActiveAccount",
|
|
13
18
|
"useEventFactory",
|
|
19
|
+
"useEventModel",
|
|
14
20
|
"useEventStore",
|
|
21
|
+
"useForceUpdate",
|
|
22
|
+
"useLayoutObservable",
|
|
23
|
+
"useLayoutObservableState",
|
|
24
|
+
"useLayoutSubscription",
|
|
15
25
|
"useObservable",
|
|
16
|
-
"
|
|
26
|
+
"useObservableCallback",
|
|
27
|
+
"useObservableEagerMemo",
|
|
28
|
+
"useObservableEagerState",
|
|
29
|
+
"useObservableGetState",
|
|
30
|
+
"useObservableMemo",
|
|
31
|
+
"useObservablePickState",
|
|
32
|
+
"useObservableRef",
|
|
33
|
+
"useObservableState",
|
|
34
|
+
"useObservableSuspense",
|
|
35
|
+
"useRefFn",
|
|
17
36
|
"useRenderNast",
|
|
37
|
+
"useRenderThrow",
|
|
18
38
|
"useRenderedContent",
|
|
19
|
-
"
|
|
39
|
+
"useSubscription",
|
|
20
40
|
]
|
|
21
41
|
`);
|
|
22
42
|
});
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ export * from "./use-action-hub.js";
|
|
|
4
4
|
export * from "./use-action.js";
|
|
5
5
|
export * from "./use-active-account.js";
|
|
6
6
|
export * from "./use-event-factory.js";
|
|
7
|
+
export * from "./use-event-model.js";
|
|
7
8
|
export * from "./use-event-store.js";
|
|
9
|
+
export * from "./use-observable-memo.js";
|
|
8
10
|
export * from "./use-observable.js";
|
|
9
|
-
export * from "./use-query-store.js";
|
|
10
11
|
export * from "./use-render-nast.js";
|
|
11
12
|
export * from "./use-rendered-content.js";
|
|
12
|
-
export * from "./use-store-query.js";
|
package/dist/hooks/index.js
CHANGED
|
@@ -4,9 +4,9 @@ export * from "./use-action-hub.js";
|
|
|
4
4
|
export * from "./use-action.js";
|
|
5
5
|
export * from "./use-active-account.js";
|
|
6
6
|
export * from "./use-event-factory.js";
|
|
7
|
+
export * from "./use-event-model.js";
|
|
7
8
|
export * from "./use-event-store.js";
|
|
9
|
+
export * from "./use-observable-memo.js";
|
|
8
10
|
export * from "./use-observable.js";
|
|
9
|
-
export * from "./use-query-store.js";
|
|
10
11
|
export * from "./use-render-nast.js";
|
|
11
12
|
export * from "./use-rendered-content.js";
|
|
12
|
-
export * from "./use-store-query.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { withImmediateValueOrDefault } from "applesauce-core";
|
|
2
|
+
import { useObservableEagerState } from "observable-hooks";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { of } from "rxjs";
|
|
5
|
+
import { useEventStore } from "./use-event-store.js";
|
|
6
|
+
/** Runs and subscribes to a model on the event store */
|
|
7
|
+
export function useEventModel(factory, args) {
|
|
8
|
+
const store = useEventStore();
|
|
9
|
+
const observable$ = useMemo(() => {
|
|
10
|
+
if (args)
|
|
11
|
+
return store.model(factory, ...args).pipe(withImmediateValueOrDefault(undefined));
|
|
12
|
+
else
|
|
13
|
+
return of(undefined);
|
|
14
|
+
}, [args, store]);
|
|
15
|
+
return useObservableEagerState(observable$);
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BehaviorSubject, Observable } from "rxjs";
|
|
2
|
+
/** A hook that recreates an observable when the dependencies change */
|
|
3
|
+
export declare function useObservableMemo<T>(factory: () => BehaviorSubject<T>, deps: any[]): T;
|
|
4
|
+
export declare function useObservableMemo<T>(factory: () => Observable<T> | undefined, deps: any[]): T | undefined;
|
|
5
|
+
/** A hook that recreates a synchronous observable when the dependencies change */
|
|
6
|
+
export declare function useObservableEagerMemo<T>(factory: () => Observable<T>, deps: any[]): T;
|
|
7
|
+
export declare function useObservableEagerMemo<T>(factory: () => Observable<T> | undefined, deps: any[]): T | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useObservableEagerState, useObservableState } from "observable-hooks";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { EMPTY } from "rxjs";
|
|
4
|
+
export function useObservableMemo(factory, deps) {
|
|
5
|
+
return useObservableState(useMemo(() => factory() || EMPTY, deps));
|
|
6
|
+
}
|
|
7
|
+
export function useObservableEagerMemo(factory, deps) {
|
|
8
|
+
return useObservableEagerState(useMemo(() => factory() || EMPTY, deps));
|
|
9
|
+
}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/** A thing wrapper around useObservableState that allows undefined */
|
|
3
|
-
export declare function useObservable<T extends unknown>(observable?: BehaviorSubject<T>): T;
|
|
4
|
-
export declare function useObservable<T extends unknown>(observable?: Observable<T>): T | undefined;
|
|
1
|
+
export * from "observable-hooks";
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export function useObservable(observable) {
|
|
4
|
-
return useObservableState(observable ?? EMPTY);
|
|
5
|
-
}
|
|
1
|
+
// NOTE: re-export hooks from observable-hooks to avoid confusion
|
|
2
|
+
export * from "observable-hooks";
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
-
import { IEventStore
|
|
3
|
-
export declare const QueryStoreContext: import("react").Context<QueryStore | null>;
|
|
2
|
+
import { IEventStore } from "applesauce-core";
|
|
4
3
|
export declare const EventStoreContext: import("react").Context<IEventStore | null>;
|
|
5
4
|
/** Provides a EventStore to the component tree */
|
|
6
5
|
export declare function EventStoreProvider({ eventStore, children }: PropsWithChildren<{
|
|
7
6
|
eventStore: IEventStore;
|
|
8
7
|
}>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
/** Provides a QueryStore and EventStore to the component tree */
|
|
10
|
-
export declare function QueryStoreProvider({ queryStore, children }: PropsWithChildren<{
|
|
11
|
-
queryStore: QueryStore;
|
|
12
|
-
}>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createContext } from "react";
|
|
3
|
-
export const QueryStoreContext = createContext(null);
|
|
4
3
|
export const EventStoreContext = createContext(null);
|
|
5
4
|
/** Provides a EventStore to the component tree */
|
|
6
5
|
export function EventStoreProvider({ eventStore, children }) {
|
|
7
6
|
return _jsx(EventStoreContext.Provider, { value: eventStore, children: children });
|
|
8
7
|
}
|
|
9
|
-
/** Provides a QueryStore and EventStore to the component tree */
|
|
10
|
-
export function QueryStoreProvider({ queryStore, children }) {
|
|
11
|
-
return (_jsx(EventStoreProvider, { eventStore: queryStore.store, children: _jsx(QueryStoreContext.Provider, { value: queryStore, children: children }) }));
|
|
12
|
-
}
|
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-20250606170247",
|
|
4
4
|
"description": "React hooks for applesauce",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,11 +49,11 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"applesauce-accounts": "0.0.0-next-
|
|
53
|
-
"applesauce-actions": "0.0.0-next-
|
|
54
|
-
"applesauce-content": "0.0.0-next-
|
|
55
|
-
"applesauce-core": "0.0.0-next-
|
|
56
|
-
"applesauce-factory": "0.0.0-next-
|
|
52
|
+
"applesauce-accounts": "0.0.0-next-20250606170247",
|
|
53
|
+
"applesauce-actions": "0.0.0-next-20250606170247",
|
|
54
|
+
"applesauce-content": "0.0.0-next-20250606170247",
|
|
55
|
+
"applesauce-core": "0.0.0-next-20250606170247",
|
|
56
|
+
"applesauce-factory": "0.0.0-next-20250606170247",
|
|
57
57
|
"nostr-tools": "^2.13",
|
|
58
58
|
"observable-hooks": "^4.2.4",
|
|
59
59
|
"react": "^18.3.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useActiveAccount(): unknown;
|
package/dist/provider.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { QueryStore } from "applesauce-core";
|
|
2
|
-
import { PropsWithChildren } from "react";
|
|
3
|
-
export declare const QueryStoreContext: import("react").Context<QueryStore | null>;
|
|
4
|
-
/** Provides a QueryStore to the component tree */
|
|
5
|
-
export declare function QueryStoreProvider({ store, children }: PropsWithChildren<{
|
|
6
|
-
store: QueryStore;
|
|
7
|
-
}>): import("react/jsx-runtime").JSX.Element;
|
package/dist/provider.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext } from "react";
|
|
3
|
-
export const QueryStoreContext = createContext(null);
|
|
4
|
-
/** Provides a QueryStore to the component tree */
|
|
5
|
-
export function QueryStoreProvider({ store, children }) {
|
|
6
|
-
return _jsx(QueryStoreContext.Provider, { value: store, children: children });
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { QueryStore } from "applesauce-core";
|
|
2
|
-
import { PropsWithChildren } from "react";
|
|
3
|
-
export declare const QueryStoreContext: import("react").Context<QueryStore | null>;
|
|
4
|
-
/** Provides a QueryStore to the component tree */
|
|
5
|
-
export declare function QueryStoreProvider({ store, children }: PropsWithChildren<{
|
|
6
|
-
store: QueryStore;
|
|
7
|
-
}>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext } from "react";
|
|
3
|
-
export const QueryStoreContext = createContext(null);
|
|
4
|
-
/** Provides a QueryStore to the component tree */
|
|
5
|
-
export function QueryStoreProvider({ store, children }) {
|
|
6
|
-
return _jsx(QueryStoreContext.Provider, { value: store, children: children });
|
|
7
|
-
}
|