arximboldi / lager

C++ library for value-oriented design using the unidirectional data-flow architecture — Redux for C++
https://sinusoid.es/lager/
MIT License
709 stars 66 forks source link

Confusion about basic example (reducer not used?) #104

Open altschuler opened 3 years ago

altschuler commented 3 years ago

In the Architecture section of the docs, a simple example program is constructed using lager::with_manual_event_loop.

I'm confused because the update function that is created in that example (and in the std version of the counter program in /examples), does not seem to be used anywhere. The simple manual event loop which takes character inputs from stdin, creates an action using the intent function and dispatches an action in the store, but how would the store to know that it should run the actions through the update function?

I suspect that the stdin-based event loop should call the update and set its state using the new state, but I might just be missing something?

Thanks!

EDIT: When looking at https://github.com/arximboldi/lager/commit/3a9733cf6d01659d6730e108511a3fbf019021d2 I realized it was a namespace issue; it worked after I put the update function into the same namespace as the model.

I'm a C++ rookie, so this might be something obvious, but it had me very confused, so might be worth documenting :)

arximboldi commented 3 years ago

Cool, thanks! You are right, this should be part of the documentation. This was a recent API change and did not fully integrate this in the documentation.

In C++ there is this rule called "ADL", which means that a function that is part of the same namespace of a type, it is part of the interface of that type, and you can use it without explicitly writing the namespace when you pass it arguments form that namespace. Note that you can also explictly pass with_reducer(...) to explitly pass a reducer, but by default, update(model, action) will be used by convention, which makes sense in most cases.

Thanks for reporting the issue. I'll leave this open as a reminder to add clearer documentation on this!

altschuler commented 3 years ago

Oops sorry, accidentally closed this