Skip to content

Instantly share code, notes, and snippets.

View chenglou's full-sized avatar
💫

Cheng Lou chenglou

💫
View GitHub Profile
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule bsPlatformBuffer
* @flow
* @whateverPragmaHere
*/
'use strict';
❯ npm uninstall --save-dev webpack
- acorn@3.3.0 node_modules/acorn
- amdefine@1.0.1 node_modules/amdefine
- arr-flatten@1.0.1 node_modules/arr-flatten
- arr-diff@2.0.0 node_modules/arr-diff
- array-unique@0.2.1 node_modules/array-unique
- arrify@1.0.1 node_modules/arrify
- async@1.5.2 node_modules/async
- async-each@1.0.1 node_modules/async-each
- balanced-match@0.4.2 node_modules/balanced-match
[@@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";
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
/*
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>
// 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 :
/* 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 / .zshrc
Created August 31, 2017 06:49
Auto-fu installation instructions
# npm/make/brew autocompletions are super slow. Disable them so that auto-fu's
# completion doesn't trigger for these
noopt() {}
compdef noopt npm
compdef noopt make
compdef noopt brew
# Fork with cleaned-up readme:
# https://github.com/HerringtonDarkholme/auto-fu.zsh
@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;
@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