It is impossible to reliably attach a fine-grained callback (subscription.on(...)=>{} ) on ndk svelte store subscriptions.
Purpose: storeSubscriptions are great to handle a collection of Svelte components but sometimes it is necessary to react with extra logic on the newest unique event that arrived. E.g. render a list of components of which one might belong to the user and the app has to react based on this one event that may be present or not.
Cause: store.subscription is undefined unitl startSubscription() is called. It is not possible to attach a callback before the subsciption start therefore. If the callback is attached AFTER startSubscription() then some events will be missed by the callback by that time.
Fix: Everything is already given in the storeSubscribe() method to assign value to store.subscription (filters, opts). The assignment code in startSubscription() should be moved in this method.
It is impossible to reliably attach a fine-grained callback (subscription.on(...)=>{} ) on ndk svelte store subscriptions.
Purpose: storeSubscriptions are great to handle a collection of Svelte components but sometimes it is necessary to react with extra logic on the newest unique event that arrived. E.g. render a list of components of which one might belong to the user and the app has to react based on this one event that may be present or not.
Cause: store.subscription is undefined unitl startSubscription() is called. It is not possible to attach a callback before the subsciption start therefore. If the callback is attached AFTER startSubscription() then some events will be missed by the callback by that time.
Fix: Everything is already given in the storeSubscribe() method to assign value to store.subscription (filters, opts). The assignment code in startSubscription() should be moved in this method.