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.
@@ -14,8 +14,6 @@ describe("exports", () => {
14
14
  "FactoryProvider",
15
15
  "Helpers",
16
16
  "Hooks",
17
- "QueryStoreContext",
18
- "QueryStoreProvider",
19
17
  ]
20
18
  `);
21
19
  });
@@ -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
- "useQueryStore",
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
- "useStoreQuery",
39
+ "useSubscription",
20
40
  ]
21
41
  `);
22
42
  });
@@ -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";
@@ -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,3 @@
1
+ import { ModelConstructor } from "applesauce-core";
2
+ /** Runs and subscribes to a model on the event store */
3
+ export declare function useEventModel<T extends unknown, Args extends Array<any>>(factory: ModelConstructor<T, Args>, args?: Args | null): T | undefined;
@@ -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
- import { type BehaviorSubject, type Observable } from "rxjs";
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
- import { useObservableState } from "observable-hooks";
2
- import { EMPTY } from "rxjs";
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";
@@ -2,4 +2,4 @@
2
2
  * Gets the QueryStore from a parent {@link QueryStoreProvider} component
3
3
  * If there is none it throws an error
4
4
  */
5
- export declare function useQueryStore(): import("applesauce-core").QueryStore;
5
+ export declare function useQueryStore(): any;
@@ -12,8 +12,6 @@ describe("exports", () => {
12
12
  "EventStoreProvider",
13
13
  "FactoryContext",
14
14
  "FactoryProvider",
15
- "QueryStoreContext",
16
- "QueryStoreProvider",
17
15
  ]
18
16
  `);
19
17
  });
@@ -1,12 +1,7 @@
1
1
  import { PropsWithChildren } from "react";
2
- import { IEventStore, QueryStore } from "applesauce-core";
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-20250522030625",
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-20250522030625",
53
- "applesauce-actions": "0.0.0-next-20250522030625",
54
- "applesauce-content": "0.0.0-next-20250522030625",
55
- "applesauce-core": "0.0.0-next-20250522030625",
56
- "applesauce-factory": "0.0.0-next-20250522030625",
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;
@@ -1,6 +0,0 @@
1
- import { useObservable } from "./use-observable.js";
2
- import { useAccountManager } from "./use-account-manager.js";
3
- export function useActiveAccount() {
4
- const manager = useAccountManager();
5
- return useObservable(manager?.active$);
6
- }
@@ -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
- }