Skip to content

Instantly share code, notes, and snippets.

View javarouka's full-sized avatar
🎯
Focusing

Yi, Hangehee javarouka

🎯
Focusing
View GitHub Profile
@javarouka
javarouka / timeBomb.js
Last active May 15, 2017 15:51
play promise post example code
const timeBomb = (millis, misfire =_=> {}) => new Promise( (resolve, reject) => {
setTimeout( () => misfire() ? resolve() : reject(), millis );
});
@javarouka
javarouka / executeBeforeTimeout.js
Created May 14, 2017 16:23
play promise post example
function executeBeforeTimeout(thenable, millis) {
return Promise.race([
Promise.resolve(thenable), // 혹시 thenable 하지 않더라도, 명시적으로 Promise 로 변경해준다.
timeBomb(millis) // 위에 정의한 지연폭탄
]);
}
@javarouka
javarouka / isThenable.js
Last active May 15, 2017 15:46
javarouka js code
function isThenable(obj) {
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
}
@javarouka
javarouka / deferredEventer.js
Last active May 24, 2017 16:19
play promise post example
function deferredEventer() {
// event map.
// 이벤트들은 이름 하나당 Set 의 구조를 가진다.
const eventMap = new Map();
return new class {
/**
* 이벤트를 예약한다.
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
function applyClipboard(element, selector) {
// implements ...
}
/**
* @Usage
* class SomeComponent extends Component {}
@javarouka
javarouka / route.js
Last active June 6, 2017 15:42
createAsyncRoute.js
import React from 'react'
import { Route } from 'react-router-dom'
import { routes } from './routeMap'
import Bundle from 'component/bundle/Bundle'
import LoadingIndicator from 'component/bundle/LoadingIndicator'
const AsyncRoute = ({ component: Component, store, ...rest }) => (
<Route {...rest} render={props => (
<Bundle store={store} load={Component}>
{(Component) => {
@javarouka
javarouka / routeMap.js
Created June 6, 2017 15:44
dynamic-route with react-router 4.x
import { injectReducer } from 'store/createRootReducer'
const appendReducer = (store, key, reducerModule) => {
const reducer = reducerModule.default || reducerModule;
injectReducer(store, { key, reducer });
};
// TODO: 계층형 라우팅 추가 필요
export const routes = [
{
class Diff extends React.Component {
constructor(props) {
super(props);
this.name = "HaHa!"
}
handleArrow = () => {
console.log(this.name);
};
const Test = (_ => {
const weakMap = new WeakMap();
return class {
constructor() {
weakMap.set(this, _=> console.log('test'))
}
doMethod() {
weakMap.get(this)();
}
};
@javarouka
javarouka / foucs.js
Last active July 19, 2017 06:27
forAsdf
class SomeContainer extends Component {
state = { value: '' };
changeText = (e) => this.setState({
value: e.target.value
});
componentDidMount() {
this.props.findOrder({ orderId: 100012134 });