Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
altschuler opened this issue Apr 3, 2021 · 2 comments
Open

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

altschuler opened this issue Apr 3, 2021 · 2 comments

Comments

@altschuler
Copy link
Contributor

altschuler commented Apr 3, 2021

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 3a9733c 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
Copy link
Owner

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
Copy link
Contributor Author

Oops sorry, accidentally closed this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants