Skip to content

Instantly share code, notes, and snippets.

View chenglou's full-sized avatar
💫

Cheng Lou chenglou

💫
View GitHub Profile
@chenglou
chenglou / foo.md
Last active June 2, 2018 02:57
bug
title
Reason 3.2.0

This release is best used in conjunction with upgrading your project to bs-platform 3.1.4.

Rejoice! The release you've all been waiting for. This fixes bring three major quality-of-life improvements when using Reason's formatter, refmt.

Foo

@chenglou
chenglou / smartestSortEver.js
Created July 7, 2013 23:36
Based on the idea of a random person on the web, comes the best sort the world has, and will, ever know.
function timeSort(array) {
array.forEach(function(item) {
setTimeout(function() {
console.log(item);
}, item);
});
}
timeSort([10,4,6,2,3,5]);
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 */
@chenglou
chenglou / batching.md
Last active December 16, 2017 03:50
Getting batched re-rerendering back

Problem Setup

Assuming JS (this transfers to ReasonReact too): owner renders <Child onClick={this.onClick} />. Child renders <div onClick={this.onClick} />.

Upon div DOM click event:

  • Child's onClick is called, sets its state for whatever purpose, then call this.props.onClick (from owner)
  • Child re-renders following setState
  • Owner's onClick sets owner's own state for whatever purpose
  • Owner re-renders following setState
  • Owner re-render causes Child to re-render again
/* Template for proposals to update the syntax. Base template: https://gist.github.com/jordwalke/6935739b74eb9b8496670cc7860f5acf */
let a = 10;
let b = 20;
/* A */
let nonNamed = (a, b) => a + b;
type nonNamed = (int, int) => int;
@chenglou
chenglou / alternative1.re
Last active September 7, 2017 12:42
Revised syntax labelled function argument. **The only difference is between ~ and :**
/* == definition == */
/* two labelled arguments, one unlabelled */
let display = (~message, ~person, time) => 1;
/* with default value */
let display = (~message="hello", ~person="Reason", time) => 1;
/* with type annotation */
let display = (~message: string, ~person: string, time: float) => 1;
/* type annoation and with default */
let display = (~message: string="hello", ~person: string="Reason", time: float) => 1;
// Generated by BUCKLESCRIPT VERSION 1.7.5, PLEASE EDIT WITH CARE
'use strict';
function counter(state, action) {
var match = action.type;
switch (match) {
case 0 :
return state + 1 | 0;
case 1 :
/*
Before: <Foo /> => Foo.make [||]
<Foo> bar </Foo> => Foo.make [|bar|]
After: <Foo /> => Foo.make ()
<Foo> bar </Foo> => Foo.make bar
*/
/* no key warning, because children isn't wrapping n times after being passed down */
/* currently needs the desugared non-jsx form */
<div> children </div>
let bumpCount a=> {
print_endline "Bumping the number!";
a+1;
};
/* refmt --in-place theFile.re */
let bumpCount a => {
print_endline "Bumping the number!";
a + 1
[@@bs.module "Run"] external onUnload : (unit => unit) => unit = "";
[@@bs.module "MyBootConfig"] external globalDelete : bool = "RickyGlobalDeleteGK";
[@@bs.module] external jordanRTCCallButton : ReactRe.reactClass = "RickyRTCCallButton.react";
[@@bs.module] [@@bs.splice] external cxRe : array string => string = "cx";
[@@bs.module] [@@bs.splice] external pureStoreBasedStateMixin : array RickyStoreRe.t => 'a =
"PureStoreBasedStateMixin";