Closed Schwartz10 closed 5 years ago
Thanks for opening your first issue in aragonJS! Someone will circle back soon ⚡
Ah yes, this is an interesting misconception I haven't really thought about (and likely @bpierre too).
You are correct that 2. is the desired behaviour! Wondering if you might be able to patch up @aragon/api-react
's readme to make this a bit more clear?
The flow of data is always meant to be
Frontend components
^
|
api.reducer (frontend; api-react)
^
|
cached
|
app.store() (script; api)
This additional frontend reducer is meant to take the cached state from the script and marshall it into a form that is friendly to the frontend's components (e.g. converting dates to Date
objects, number strings to BN
objects or native numbers, etc.)
I think this is more of a question/clarification with the react-api docs rather than a bug report.
From this example in the aragon react-api docs, it's suggested that the
AragonApi
react component takes areducer
prop. My understanding is that thereducer
function can hear of state updates from the backgroundscript.js
, and dispatch state updates to persist (why else would you return a new state?). AKA, if I return a new state from theAragonApi
reducer, the next state as seen in the AragonApi and the script.js file should represent that new state. I'm currently running"@aragon/api-react": "^1.0.0-beta.1"
and this is not the case.A more deatiled example:
Initially when my application loads, the reducer in the front-end code (
index.js
) fires with a state ofnull
, as expected. Following the docs,if (state === null)
I return aninitialState
. However, upon subsequent calls to this reducer, the state is stillnull
. TheinitialState
is not set in thescript.js
file either. The only time the state variable updates in thereducer
(passed to theAragonApi
), is when thescript.js
reducer returns a new state after theINITIALIZATION_TRIGGER
event gets fired.To make things clearer, I have 2 opinions on this:
<AragonApi />
should be able to dispatch updates to the global app state<AragonApi />
is actually read-only - it can't dispatch new updates.My intuition is that number 2 is the desired behavior - because no
event
is passed to the reducer either, making it very difficult to properly update state. Thanks for any help and let me know if i can clarify anything further!