File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,8 @@ export const getCollection = <State>(
2727 subscribeUpdates ?: (
2828 conn : Connection ,
2929 store : Store < State >
30- ) => Promise < UnsubscribeFunc >
30+ ) => Promise < UnsubscribeFunc > ,
31+ options : { unsubGrace : boolean } = { unsubGrace : true }
3132) : Collection < State > => {
3233 if ( conn [ key ] ) {
3334 return conn [ key ] ;
@@ -93,6 +94,7 @@ export const getCollection = <State>(
9394 unsubProm . then ( ( unsub ) => {
9495 unsub ( ) ;
9596 } ) ;
97+ store . clearState ( ) ;
9698 conn . removeEventListener ( "ready" , refresh ) ;
9799 conn . removeEventListener ( "disconnected" , handleDisconnect ) ;
98100 } ;
@@ -149,7 +151,9 @@ export const getCollection = <State>(
149151 }
150152
151153 if ( ! active ) {
152- scheduleTeardownUpdateSubscription ( ) ;
154+ options . unsubGrace
155+ ? scheduleTeardownUpdateSubscription ( )
156+ : teardownUpdateSubscription ( ) ;
153157 }
154158 } ;
155159 } ,
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export type Store<State> = {
1515 state : State | undefined ;
1616 action ( action : Action < State > ) : BoundAction < State > ;
1717 setState ( update : Partial < State > , overwrite ?: boolean ) : void ;
18+ clearState ( ) : void ;
1819 subscribe ( listener : Listener < State > ) : UnsubscribeFunc ;
1920} ;
2021
@@ -82,12 +83,16 @@ export const createStore = <State>(state?: State): Store<State> => {
8283 */
8384 setState,
8485
86+ clearState ( ) {
87+ state = undefined ;
88+ } ,
89+
8590 /**
8691 * Register a listener function to be called whenever state is changed. Returns an `unsubscribe()` function.
8792 * @param {Function } listener A function to call when state changes. Gets passed the new state.
8893 * @returns {Function } unsubscribe()
8994 */
90- subscribe ( listener : Listener < State > ) {
95+ subscribe ( listener : Listener < State > ) : UnsubscribeFunc {
9196 listeners . push ( listener ) ;
9297 return ( ) => {
9398 unsubscribe ( listener ) ;
You can’t perform that action at this time.
0 commit comments