Closed emircanerkul closed 1 year ago
@tncrazvan I see why this happen. There is a cache per event subscriber. Each time if the data same, the subscriber can not catch it.
Observed th problem via
emit(EVENT_ENTITY_OUT_OF_SIGHT, JSON.stringify({...entity, date:Date.now}));
@tncrazvan I see why this happen. There is a cache per event subscriber. Each time if the data same, the subscriber can not catch it.
Observed th problem via
emit(EVENT_ENTITY_OUT_OF_SIGHT, JSON.stringify({...entity, date:Date.now}));
Yes, svelte stores will check for safe_not_equal
before emitting data.
The background event will still send data over the wire.
So, @tncrazvan how can I catch all of those changes? Is there any easy way to override (duplicate) the Svelte runtime store and change in your extension?
Duplicating is easy but also need to change your code (/sveltekit-sse/dist/source.js) too, is there any other easy way?
Version 0.3.0
is out.
I've been working all day on this, let me know if this fixes your problem (it should and more).
I've added a new method source::select::transform
to the api.
Once you select your event you can now call transform
on it and convert it to whatever object you want in real time.
Each transform
receives a ReadableStream<string>
as a parameter
const connection = source('/events')
const data = connection.select('my-event').transform((stream)=>{
// your code here...
})
Whatever your callback returns is what you'll get in your const data
.
In your case you wanted your store to not filter duplicate messages.
To do that you need to create a custom svelte store.
Note\ If you don't know how to create a custom store I suggest you read this. It's nothing fancy, but you need to understand the svelte store contract.
That being said you can find a full working example in the main README.md file.
I'll also leave here this permalink in case you wanna check the commit.
Result:
@tncrazvan thank you a lot. Your new version worked great. Maybe the possibility of setting the default transformer would be good but it just some spice.
connection.select(EVENT_CURRENT_ENTITY_UPDATE).transform(transformer).subscribe
The server sends the data in the correct order, but listeners could not catch time to time.