From 35efc44f31be24f051e9afe52d69be540d212e52 Mon Sep 17 00:00:00 2001 From: JuliusKoronciCH <165957874+JuliusKoronciCH@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:37:03 +0200 Subject: [PATCH 1/2] expose event store (#8) --- lib/event-store.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) 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$, }; } From 2c689efd0828e5ceff3ed8f18efd0dc2e8345bc7 Mon Sep 17 00:00:00 2001 From: JuliusKoronciCH Date: Thu, 4 Apr 2024 11:38:53 +0000 Subject: [PATCH 2/2] chore(release): 0.0.2-beta.7 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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/package.json b/package.json index 899bfdb..7939f51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dantian", - "version": "0.0.2-beta.6", + "version": "0.0.2-beta.7", "type": "module", "main": "./dist/dantian.cjs", "module": "./dist/dantian.js",