woeps / refabricator

Static Site Generator for/in ReasonML
MIT License
30 stars 1 forks source link

(Reactive) Streams? #29

Open woeps opened 4 years ago

woeps commented 4 years ago

The current implementation sometimes feels like a bad rough implementation of something similar to reactive streams. - so why not go the full mile and actually use an established strems library?

I'd be very much interested in some opinnions!


Some libraries I found:

woeps commented 4 years ago

After a little reading into the libraries, I would lean towards usint React.E

Types

In relation to #18 : Types could be changed to something like:

type meta = { name: string };
type fabric('t) = (meta, 't);
type fabricator('out) = React.E.t(fabric('out));
type refabricator('in, 'out) = React.E.t(fabric('in)) => React.t(fabric('out)); // this will be usually done by using React's lifting functions
type factory('in, 'outOk, 'outErr) = React.E.t(fabric('in)) => React.E.t(fabric(Result.t('outOk, 'outErr)));

Refabricator Constructor

Additionally a constructor for refabricators could be provided like:

let makeRefabricator: (fabric('in) => fabric('out)) => Types.refabricator('in, out) = React.E.l1;

This means just implementing the map function is enough.

Error Handling

String

I'm not sure though how to handles errors in (re-) fabricators. Maybe limit a factories error type to just string and ok to just the fabric? (Re-) fabricators could send the same result type. Errors Would be passed through.

This means only the component which runs into the error could handle or compensate it accordingly. Having compensations in another component would mean matching and de-/serializing a string, which is't a good idea.

Polymorphic Variant

Or just use polymorphic variants and define some common errors in Types.error. In this case every component will need to handle all commonly defined errors and/or pass every other polymorphic variant through to the next component.

This would probably mean factory would become obsolete, because its just a refabricator. Lib.Main would then add a print function which takes a list of pp ("pretty print") functions:

type pp_error('e) => ('e => string);
let errorsToString: list(pp_error) => string;

This would mean any custom component could implement it's own pp_error function and add it as an argument to errorsToString.

A default pp_error function for the common errors could be "pre-injected" into a helper function to errorsToString.

woeps commented 4 years ago

I started experimenting with React on the experiment/react branch. Once I have a good understanding of how I want to use React, I'll send a separate PR switching everything over to using React.

woeps commented 4 years ago

I started experimenting with Lwt_stream on experiment/lwt-stream branch. Will try some more things there.

I probably should try Lwt_react as well.