Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to manually re-trigger the getter? #9

Closed
felixakiragreen opened this issue Aug 5, 2021 · 2 comments
Closed

Is there a way to manually re-trigger the getter? #9

felixakiragreen opened this issue Aug 5, 2021 · 2 comments

Comments

@felixakiragreen
Copy link

My use-case:

I'm fetching a list of events from an API.

Separately, I've subscribed to another service which triggers a notification when there are new events.

After I've received the notification, I want to re-fetch the list of events, which should now have the new one, which will update the UI.

@PaulMaly
Copy link
Member

PaulMaly commented Sep 13, 2021

Hi @felixakiragreen ! Sorry for the late answer, I'd missed it somehow or forgot about it.

Anyway, I'll try to produce your situation using svelte-asyncable and svelte-streamable (SSE store):

import { streamable } from 'svelte-streamable';
import { asyncable } from 'svelte-asyncable';

const eventsNotifier = streamable({ 
    url: 'http://xxx.xxx.xxx:xxx/notifications',
    event: 'events',
});
...
const events = asyncable(fetchEvents, null, [ eventsNotifier ]);
...

So, that's it. Every time when eventsNotifier store will be changed it will re-call events store getter because it's specified as a dependency of asyncable store.

But I'm sure you use another tool for your notifications, but still you can create a regular writable/readable store and pass it in 3rd argument of asyncable store. Anytime dependant stores have changed, asyncable getter will be performed automatically with new values of that stores.

Hope I'm answered your question, better late than never.

@felixakiragreen
Copy link
Author

Thank you! This is exactly what I needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants