Last active
February 15, 2018 04:38
-
-
Save persianturtle/140324080e7fc9ecb72f950d6c0d12ce to your computer and use it in GitHub Desktop.
Partial from reducer field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[@bs.val] [@bs.scope "performance"] external now : unit => float = ""; | |
... | |
| TouchStart(clientX) => | |
if (state.nav.isOpen) { | |
state.nav.isSwiping := true; | |
}; | |
ReasonReact.Update({ | |
...state, | |
nav: { | |
...state.nav, | |
position: [(clientX, now())] | |
} | |
}); | |
| TouchMove(clientX) => | |
if (state.nav.isSwiping^) { | |
ReasonReact.Update({ | |
...state, | |
nav: { | |
...state.nav, | |
position: [(clientX, now()), ...state.nav.position] | |
} | |
}); | |
} else { | |
ReasonReact.NoUpdate; | |
} | |
| TouchEnd(clientX) => | |
state.nav.isSwiping := false; | |
let velocity = | |
switch state.nav.position { | |
| [] => 0.0 | |
| [_] => 0.0 | |
| [(x', t'), (x, t), ..._] => (x' -. x) /. (t' -. t) | |
}; | |
if (velocity < (-0.3)) { | |
ReasonReact.Update({ | |
...state, | |
nav: { | |
...state.nav, | |
isOpen: false | |
} | |
}); | |
} else if (clientX < 300.0 /. 2.0) { | |
ReasonReact.Update({ | |
...state, | |
nav: { | |
...state.nav, | |
isOpen: false | |
} | |
}); | |
} else { | |
ReasonReact.Update(state); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment