Fork me on GitHub
#om
<
2017-02-09
>
baptiste-from-paris18:02:22

Question : I’ve seen in the official docs and elsewhere that local mutations where discouraged outside styling/animation. I often using this kind of code

(dom/input #js {
    :type     “type”
    :name     "first-name"
    :value    (or (om/get-state this [:new-player :first-name]) "")
    :onChange (fn [e]
                          (om/update-state! this assoc-in
                            [:new-player :first-name]
                            (.. e -target -value)))})

baptiste-from-paris18:02:00

I understand the risks but I’d like to know what are the trends

baptiste-from-paris18:02:21

do you guys use the app-state for updating an input or not ?

drcode19:02:41

@baptiste-from-paris I do it the same way you're doing it

drcode19:02:51

Imagine your app had an "undo" button (maybe it does) and then ask yourself: Is this an action I want the user to be able to undo with an explicit undo step? If the answer is "yes" put it in app state. If the answer is "no" put it in local state.

drcode19:02:34

Key presses in an input are usually not something you'd expect to be able to undo a keypress at a time.

drcode19:02:07

Another similar heuristic I use is "If the updates typically happen multiple times a second, use local state. If they are less frequent, use app state". This means that anything involving keyboard typing or animation should use local state

baptiste-from-paris19:02:24

what do you guys use for rapid application developemnt (untangles ? css framework ? React librairies) ?