Skip to content

Instantly share code, notes, and snippets.

View persianturtle's full-sized avatar

Raphael Rafatpanah persianturtle

View GitHub Profile
const https = require('https')
const options = {
hostname: 'example.com',
port: 443,
method: 'PUT',
headers: {
'Content-Type': '<whatever>',
Authorization:
'Bearer <token>',
@persianturtle
persianturtle / app.re
Last active February 15, 2018 04:38
Partial from reducer field
[@bs.val] [@bs.scope "performance"] external now : unit => float = "";
...
| TouchStart(clientX) =>
if (state.nav.isOpen) {
state.nav.isSwiping := true;
};
ReasonReact.Update({
...state,
@persianturtle
persianturtle / app.re
Created February 15, 2018 04:27
Bind to JS' performance.now()
[@bs.val] [@bs.scope "performance"] external now : unit => float = "";
@persianturtle
persianturtle / app.re
Created February 15, 2018 03:16
partial from render field
let x = List.hd(List.rev(self.state.nav.position));
let x' = List.hd(self.state.nav.position);
...
<nav
className=(self.state.nav.isOpen ? "active" : "")
onClick=(event => ReactEventRe.Mouse.stopPropagation(event))
style=(
self.state.nav.isSwiping^ ?
@persianturtle
persianturtle / app.re
Created February 15, 2018 03:02
partial from reducer field
| TouchStart(clientX) =>
if (state.nav.isOpen) {
state.nav.isSwiping := true;
};
ReasonReact.Update({
...state,
nav: {
...state.nav,
position: [clientX]
}
let component = ReasonReact.statelessComponent("Page1");
let make = _children => {
...component,
render: _self =>
<div className="Page1">
<h1> (ReasonReact.stringToElement("Page1")) </h1>
</div>
};
@persianturtle
persianturtle / app.re
Created February 13, 2018 03:27
Just the reducer field (solution 2)
[@bs.val] [@bs.scope "document"] external documentElement : Dom.element = "";
...
reducer: (action, state) =>
switch action {
| Navigate(_routeWithTitle) => ReasonReact.NoUpdate
| ToggleMenu(isOpen) =>
ReasonReact.UpdateWithSideEffects(
{
@persianturtle
persianturtle / app.re
Created February 13, 2018 03:13
Just the reducer field (solution 1)
reducer: (action, state) =>
switch action {
| Navigate(_routeWithTitle) => ReasonReact.NoUpdate
| ToggleMenu(isOpen) =>
ReasonReact.UpdateWithSideEffects(
{
...state,
nav: {
isOpen: isOpen
}
.App:after {
content: '';
transition: opacity 450ms cubic-bezier(0.23, 1, 0.32, 1),
transform 0ms cubic-bezier(0.23, 1, 0.32, 1) 450ms;
position: fixed; top: 0; right: 0; bottom: 0; left: 0;
background-color: rgba(0, 0, 0, 0.33);
transform: translateX(-100%);
opacity: 0;
z-index: 1;
}
@persianturtle
persianturtle / app.re
Created February 13, 2018 02:24
Just the render field
render: self => {
let (route, title) = self.state.routeWithTitle;
<div
className=("App" ++ (self.state.nav.isOpen ? " overlay" : ""))
onClick=(_event => self.send(ToggleMenu(false)))>
<header>
<a
onClick=(
event => {
ReactEventRe.Mouse.stopPropagation(event);