Skip to content

Instantly share code, notes, and snippets.

View fakenickels's full-sized avatar
💭
hello this is a mic test, are you listening

Gabriel fakenickels

💭
hello this is a mic test, are you listening
View GitHub Profile
@fakenickels
fakenickels / styled.re
Created January 16, 2019 11:38
StyledPpx
module ImageWrapper = [%styled
Image;
() => [
width(Pt(100))
]
];
module Wrapper = [%styled
Image;
(~bg) => [
type hoc = ReasonReact.reactClass => ReasonReact.reactClass;
type router;
module WithRouter = {
[@bs.module "react-router"] external withRouter : hoc =
"withRouter";
type children = (~router: router) => ReasonReact.reactElement;
let component = ReasonReact.statelessComponent("WithRouter");
let make' = (~router: router, children: children) => {
module ReMotionConfig = {
type state = | Open | Closed;
let animateForState = fun | Open => [opacity(1)] | Closed => [opacity(0)];
};
module Motion = ReMotion.Make(ReMotionConfig);
<Motion state=Closed>
...(({ style, setState, state, transitioning }) => {
[{pstr_desc =
Pstr_module
{pmb_name = {txt = "FormConfig"};
pmb_expr =
{pmod_desc =
Pmod_structure
[{pstr_desc =
Pstr_type
[{ptype_name = {txt = "field"};
module FormConfig = {
type field(_) =
| Email: field(string)
| Age: field(int);
type state = {
email: string,
age: int,
};
let get: type value. (state, field(value)) => value =
module type Config = {
type field('a);
type state;
let initialState: state;
let set: (state, field('a), 'a) => state;
};
module Make = (Config: Config) => {
let state = ref(Config.initialState);
import React from 'react'
import immutagen from 'immutagen'
export default component => {
const generator = immutagen(component)
const compose = context => {
const value = context.value
return context.next
? React.cloneElement(value, null, values => compose(context.next(values)))
module type StyledWrapper = {};
let styled = (declarations, componentMake) => {
module Styled = {
let make = componentMake(~className=(Css.style(declarations)));
};
((module Styled): (module StyledWrapper));
};
module Wrapper = (val styled(Css.([padding(px(20))]), (~className) => MD.Grid.make(~className)));
@fakenickels
fakenickels / usage.js
Created May 28, 2018 13:57
Waterfall helper
const mail = (foo, t) => new Promise((resolve) => setTimeout(() => { console.log(foo); resolve() }, t))
async function doThing() {
const items = ['foo', 'bar', 'buz', 'fuz'];
await waterfall(items.map((item) => async () => { await mail('mailing' + item, 4000); }))
await mail("end", 1000)
}
module type Config = {
type state;
type fields;
let lens: list((fields, state => ReForm.Value.t, (state, ReForm.Value.t) => state));
};
module Create = (Config: Config) => {
module Form = ReForm.Create(Config);
type fieldSchema = {
field: Config.fields,