diff --git a/CHANGELOG.md b/CHANGELOG.md index b27cfb0..083b62f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/event-store.ts b/lib/event-store.ts index 88005a8..333c58f 100644 --- a/lib/event-store.ts +++ b/lib/event-store.ts @@ -26,12 +26,12 @@ export function createEventStore( }, ) { const debug = options?.debug === true ? options.debug : false; - const globalEventStore = new BehaviorSubject | SystemEvent>( - { - type: '@@INIT', - payload: initialState, - }, - ); + const globalEventStore$ = new BehaviorSubject< + NestedEvent | SystemEvent + >({ + type: '@@INIT', + payload: initialState, + }); const publish = < TType extends PropertyPath, TPayload extends GetValueType, @@ -41,13 +41,13 @@ export function createEventStore( ) => { // eslint-disable-next-line const event = { type, payload } as NestedEvent; - globalEventStore.next(event); + globalEventStore$.next(event); }; const getPropertyObservable = >( eventType: K, ): Observable> => { - return globalEventStore.pipe( + return globalEventStore$.pipe( filter((event) => event.type.startsWith(eventType)), map((event) => event.payload as GetValueType), scan((__, curr) => curr), @@ -56,7 +56,7 @@ export function createEventStore( }; const getHydrationObservable$ = (): Observable => { - return globalEventStore.pipe( + return globalEventStore$.pipe( filter((event) => event.type === '@@HYDRATED'), map((event) => event.payload as T), scan((__, curr) => curr), @@ -66,7 +66,7 @@ export function createEventStore( const state$ = new BehaviorSubject(initialState); - globalEventStore + globalEventStore$ .pipe( tap((event) => { if (debug) { @@ -91,7 +91,7 @@ export function createEventStore( options ?.hydrator?.() .then((payload) => { - globalEventStore.next({ type: '@@HYDRATED', payload }); + globalEventStore$.next({ type: '@@HYDRATED', payload }); }) .catch((error) => { console.error('Failed to hydrate store', error); @@ -135,7 +135,7 @@ export function createEventStore( }; const useHydrateStore = () => { return useCallback((payload: T) => { - globalEventStore.next({ type: '@@HYDRATED', payload }); + globalEventStore$.next({ type: '@@HYDRATED', payload }); }, []); }; const useIsHydrated = () => { @@ -154,7 +154,7 @@ export function createEventStore( return useMemo(() => isHydrated, [isHydrated]); }; - const systemEvents$ = globalEventStore.pipe( + const systemEvents$ = globalEventStore$.pipe( filter((event) => event.type.startsWith('@@')), ); @@ -166,5 +166,6 @@ export function createEventStore( getPropertyObservable, state$, systemEvents$, + globalEventStore$, }; } diff --git a/package.json b/package.json index 7d16b80..34721e3 100644 --- a/package.json +++ b/package.json @@ -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",