writer-framework icon indicating copy to clipboard operation
writer-framework copied to clipboard

Event and state serde aren't expansible

Open ramedina86 opened this issue 1 year ago • 3 comments

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).

ramedina86 avatar Jan 23 '24 15:01 ramedina86

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.

FabienArcellier avatar Jan 23 '24 20:01 FabienArcellier

Thanks Fabien; that sounds great.

Couple of questions:

  1. Why is Folium in quotes? Is this supposed to be MRO?
  2. Would change-folium-location be the name of the event?
  3. Are we maintaining a similar logic to what we have now, where we basically link an event type to a specific sanitizer?

ramedina86 avatar Jan 23 '24 20:01 ramedina86

  1. Yes it's either the MRO, either a class or a type
  2. 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)

FabienArcellier avatar Jan 24 '24 17:01 FabienArcellier