Event and state serde aren't expansible
To address this, we need a plug-in style approach for event deserialization and for state serialization. We'll need to migrate from the big IF blocks we currently have, to this.
This is a prerequisite for effective, wider-purpose extensions.
We'll need to be able to intercept/sanitize new types of events (e.g. ss-mycustomsafeevent), but also new types of objects (produced by libraries other than the supported by the core).
Hello @ramedina86, I would think to extends the extension mechanism (FabienArcellier:14-pagination-component-for-repeater-and-dataframe-2). The developper could add a file setup.py in the extension. This file would be loaded when streamsync starts if the extension is installed.
The developper could declare serializer and santitizer for event.
streamsync.register_serializer('Folium', lambda v: v.json())
streamsync.register_serializer(FileWrapper, serialize_file)
streamsync.register_sanitizer('change-folium-location', check_folium_input)
On event, I would propose to evolve the event definition and set the sanitizer as argument.
Thanks Fabien; that sounds great.
Couple of questions:
- Why is Folium in quotes? Is this supposed to be MRO?
- Would
change-folium-locationbe the name of the event? - Are we maintaining a similar logic to what we have now, where we basically link an event type to a specific sanitizer?
- Yes it's either the MRO, either a class or a type
- I take some time to think on it. I think using the event name could be great. It's easy to explain and document. There is a risk of implementing same code on different sanitizer but it's not an issue.
streamsync.register_sanitizer('ss-change-folium-location', check_folium_input)