Skip to content

Instantly share code, notes, and snippets.

@chenglou
Last active December 17, 2017 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenglou/e43f9a3c3ea924cbcf6e57f87d244f0b to your computer and use it in GitHub Desktop.
Save chenglou/e43f9a3c3ea924cbcf6e57f87d244f0b to your computer and use it in GitHub Desktop.
reducer: {
| Edit => (state) => ReasonReact.Update({...state, editText: todo.title})
| Submit => submitHelper
| Change(text) =>
(state) =>
editing ?
ReasonReact.Update({...state, editText: text}) :
ReasonReact.NoUpdate
| KeyDown(27) =>
/* escape key */
onCancel();
(state) => ReasonReact.Update({...state, editText: todo.title})
| KeyDown(13) =>
/* enter key */
submitHelper
| KeyDown(_) => state => ReasonReact.NoUpdate
}
/* swap ordering */
| KeyDown(_) => ReasonReact.NoUpdate
| Change(text) => editing ? ReasonReact.Update(state => {...state, editText: text}) : ReasonReact.NoUpdate
@jordwalke
Copy link

One downside: It's a lot more typing out of lambdas. I think it would increase the demand for a lighter weight way to register event handlers like:

<div onClick=self.reduceAction />

Just to avoid lambda fatigue.

There's ways to do that but it's a fairly invasive change.

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