Skip to content

Instantly share code, notes, and snippets.

View koba04's full-sized avatar

Toru Kobayashi koba04

View GitHub Profile
@koba04
koba04 / try-enzyme-v3-alpha.js
Last active August 7, 2017 06:41
Testing React components with React v16 beta and enzyme@3.0.0-alpha.1
const {shallow, configure} = require('enzyme');
const ReactSixteenAdapter = require('enzyme/build/adapters/ReactSixteenAdapter');
configure({adapter: new ReactSixteenAdapter()});
// your test
export type HostConfig<T, P, I, TI, PI, C, CX, PL> = {
getRootHostContext(rootContainerInstance: C): CX {
// e.g. namespace of DOM
},
getChildHostContext(parentHostContext: CX, type: T, instance: C): CX {
// e.g. namespace of DOM
},
getPublicInstance(instance: I | TI): PI {
// e.g. DOM Element
/**
* @providesModule ReactVoice
*/
'use strict';
const {spawnSync} = require('child_process');
const ReactDOMFrameScheduling = require('ReactDOMFrameScheduling');
const ReactFiberReconciler = require('ReactFiberReconciler');
const sideEffect = (method, text) => spawnSync('say', ['-v', method, text]);
@koba04
koba04 / ReactConsoleRenderer.js
Last active October 3, 2018 13:32
A minimum custom renderer implementation using ReactFiber
/**
* @providesModule ReactConsole
*/
'use strict';
const colors = require('colors');
const ReactDOMFrameScheduling = require('ReactDOMFrameScheduling');
const ReactFiberReconciler = require('ReactFiberReconciler');
@koba04
koba04 / .gitignore
Last active January 16, 2017 12:22
node_modules/
@koba04
koba04 / nginx_for_cors.conf
Last active April 26, 2016 02:19
nginx.conf for CORS
location / {
if ($http_origin = 'http://api.example.com') {
set $cors 'true';
}
if ($request_method = 'OPTIONS') {
set $cors "${cors}:options";
}
if ($request_method ~ ^(POST|GET)$) {
set $cors "${cors}:allow_methods";
}
@koba04
koba04 / keybindings.json
Last active November 19, 2015 03:09
vscode keybindings
[
{ "key": "shift+ctrl+n", "command": "cursorDownSelect",
"when": "editorTextFocus" },
{ "key": "shift+ctrl+p", "command": "cursorUpSelect",
"when": "editorTextFocus" },
{ "key": "shift+ctrl+f", "command": "cursorRightSelect",
"when": "editorTextFocus" },
{ "key": "shift+ctrl+b", "command": "cursorLeftSelect",
"when": "editorTextFocus" },
{ "key": "ctrl+n", "command": "selectNextSuggestion",
@koba04
koba04 / fakeFetch.js
Last active October 28, 2015 10:44
a minimum fake implementation of fetch on Node environment
import assign from 'object-assign';
export default function fakeFetch(res) {
global.fetch = (url, params) => {
return Promise.resolve(assign({}, res, {__arg: {url, params}}));
};
}
@koba04
koba04 / StaticComponent.js
Created April 16, 2015 01:16
React static component by higher order function.
import React from 'react';
const Static = Component => class extends React.Component {
shouldComponentUpdate() {
return false;
}
render() {
return <Component {...this.props} />;
}
};
class Sample extends React.Component {
getInitialState() {
return { data: this.props.initialData };
}
componentDidMount() {
if (!this.props.initialDada) {
request('/api/xxx')
.end((err, res) => {
this.setState({ data: res.body });
})