yahoo / jafar

🌟!(Just another form application renderer)

Home Page:https://yahoo.github.io/jafar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add updater option to changeState and changeValue actions

galhavivi opened this issue · comments

Jafar maintain a process queue - meaning in you call 3 times "onStateChange" - only after one action is done processing - the next one will start - https://yahoo.github.io/jafar/docs/pending-actions.html.
onStateChange receive an entire NEW state object and replace it completely for the field (not merge with current state object - replace) just like setState of react - https://reactjs.org/docs/react-component.html#setstate.

We should also support 'updater' option like react's 'setState' to enable updating state based on the current existing field state. i.e :

  1. changeState(fieldId, entireNewStateObject) // currently supported
  2. changeState(fieldId, (currentState) => { return { ...currentState, newData: 12345 } })

That will enable Jafar react components to call "onStateChange" multiple times and the same time (for example from few different underline components of a field ) without waiting first for the Jafar lifecycle to finish previous changeState action digest to get the updated state.

Issue example mentioned in - #50