You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was thinking I could create internal subscriptions, say to firebase, within derived store start function, like with readable stores:
exportconstposts=derived(user,($user,set)=>{if(isClient&&$user){console.log('user update, subbing posts.')constunsub=firebase.firestore().collection('posts').orderBy('createdAt','desc').onSnapshot(snap=>{console.log('posts snapshot:',snap.docs.length)set(snap.docs.map(d=>({id: d.id, ...d.data()})))})// this doesn't do anything because internally it's never called.// derived creates a readable sub from $user, and usubs from *that* outer subscription// no way for me to unsub from this *internal* subscriptionreturn()=>console.log('unsub posts')||unsub()}},undefined)
Use case would be any subscription creation that depends on values from other stores or firebase paths or auth state etc. Kind of like switchMap from rxjs... reactive all the way down.
One useful aspect of the readable store is that if you don't return a stop function, the firebase listener remains active. It'd be nice to also have this use case inside derived but you'd have to distinguish between stopping subscription when dependencies change to recreate it, and stopping when there's 0 subscribers.
The text was updated successfully, but these errors were encountered:
cdock1029
changed the title
Not stop functionality in derived stores
No stop functionality in derived stores
Apr 24, 2019
I was thinking I could create internal subscriptions, say to firebase, within derived store start function, like with readable stores:
Use case would be any subscription creation that depends on values from other stores or firebase paths or auth state etc. Kind of like
switchMap
from rxjs... reactive all the way down.One useful aspect of the readable store is that if you don't return a stop function, the firebase listener remains active. It'd be nice to also have this use case inside
derived
but you'd have to distinguish between stopping subscription when dependencies change to recreate it, and stopping when there's 0 subscribers.The text was updated successfully, but these errors were encountered: