Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliusKoronciCH committed Apr 4, 2024
2 parents fff2f61 + 2c689ef commit cc6ebf4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.0.2-beta.7 (2024-04-04)

### 0.0.2-beta.6 (2024-04-04)

### 0.0.2-beta.5 (2024-04-04)
Expand Down
27 changes: 14 additions & 13 deletions lib/event-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ export function createEventStore<T extends object>(
},
) {
const debug = options?.debug === true ? options.debug : false;
const globalEventStore = new BehaviorSubject<NestedEvent<T> | SystemEvent<T>>(
{
type: '@@INIT',
payload: initialState,
},
);
const globalEventStore$ = new BehaviorSubject<
NestedEvent<T> | SystemEvent<T>
>({
type: '@@INIT',
payload: initialState,
});
const publish = <
TType extends PropertyPath<T>,
TPayload extends GetValueType<T, TType>,
Expand All @@ -41,13 +41,13 @@ export function createEventStore<T extends object>(
) => {
// eslint-disable-next-line
const event = { type, payload } as NestedEvent<T>;
globalEventStore.next(event);
globalEventStore$.next(event);
};

const getPropertyObservable = <K extends PropertyPath<T>>(
eventType: K,
): Observable<GetValueType<T, K>> => {
return globalEventStore.pipe(
return globalEventStore$.pipe(
filter((event) => event.type.startsWith(eventType)),
map((event) => event.payload as GetValueType<T, K>),
scan((__, curr) => curr),
Expand All @@ -56,7 +56,7 @@ export function createEventStore<T extends object>(
};

const getHydrationObservable$ = (): Observable<T> => {
return globalEventStore.pipe(
return globalEventStore$.pipe(
filter((event) => event.type === '@@HYDRATED'),
map((event) => event.payload as T),
scan((__, curr) => curr),
Expand All @@ -66,7 +66,7 @@ export function createEventStore<T extends object>(

const state$ = new BehaviorSubject<T>(initialState);

globalEventStore
globalEventStore$
.pipe(
tap((event) => {
if (debug) {
Expand All @@ -91,7 +91,7 @@ export function createEventStore<T extends object>(
options
?.hydrator?.()
.then((payload) => {
globalEventStore.next({ type: '@@HYDRATED', payload });
globalEventStore$.next({ type: '@@HYDRATED', payload });
})
.catch((error) => {
console.error('Failed to hydrate store', error);
Expand Down Expand Up @@ -135,7 +135,7 @@ export function createEventStore<T extends object>(
};
const useHydrateStore = () => {
return useCallback((payload: T) => {
globalEventStore.next({ type: '@@HYDRATED', payload });
globalEventStore$.next({ type: '@@HYDRATED', payload });
}, []);
};
const useIsHydrated = () => {
Expand All @@ -154,7 +154,7 @@ export function createEventStore<T extends object>(

return useMemo(() => isHydrated, [isHydrated]);
};
const systemEvents$ = globalEventStore.pipe(
const systemEvents$ = globalEventStore$.pipe(
filter((event) => event.type.startsWith('@@')),
);

Expand All @@ -166,5 +166,6 @@ export function createEventStore<T extends object>(
getPropertyObservable,
state$,
systemEvents$,
globalEventStore$,
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dantian",
"version": "0.0.2-beta.6",
"license": "MIT",
"version": "0.0.2-beta.7",
"type": "module",
"main": "./dist/dantian.cjs",
"module": "./dist/dantian.js",
Expand Down

0 comments on commit cc6ebf4

Please sign in to comment.