GregoryConrad / rearch-rs

Re-imagined approach to application design and architecture
https://crates.io/crates/rearch
MIT License
84 stars 4 forks source link

Switch `SideEffect`s to have any input be apart of their function #13

Closed GregoryConrad closed 10 months ago

GregoryConrad commented 11 months ago

As an alternative to #3, we could perhaps rewrite side effects to use a form of fn as_listener(register: SideEffectRegistrar, _: ()) {}.

Then, you would do register((as_listener, ())), or register((effects::state, 1234), (effect2, ())).

Not sure which approach I like better. Current approach requires more code indentation (returning a closure), but this one is forced to one side effect argument at all times, and requires wrapping everything in tuples.

GregoryConrad commented 11 months ago

Too unergonomic for actual use. Easier to write side effects, but writing side effects is on the rarer side, especially for the Rust implementation.

GregoryConrad commented 11 months ago

I suppose we could also try to support an API like:

let ((state, set_state), rebuilder)= registrar
    .register(effects::state, 1234)
    .register(effects::rebuilder, ())
    .complete()

And then for one side effect we can add a convenience registrar.single(state, 1234).

Might be able to integrate with the tuple_list crate to make such an API not a total pain to implement.

GregoryConrad commented 11 months ago

We could also ship a proc macro for side effects that allows us to do:

let ((state, set_state), _) = register.state(1234).as_listener().complete();

To me, this is the best of all worlds. Won't require better-api feature gate, method chaining is declarative and readable, and GATs should no longer be an issue. Might take a crack at implementing this.

GregoryConrad commented 10 months ago

Changed my mind; this is too unergonomic and is hard to implement. It is still easier to just write out register.register((effect1(), effect2(1234))) on stable rust than this alternative is, and that API makes the impl far far easier than this one would be.