Skip to content

Instantly share code, notes, and snippets.

@Calvin-Huang
Calvin-Huang / timeoutFetch.js
Created March 14, 2017 03:30
Warp fetch with promise to reach timeout function.
// Reference from @github/fetch issue 175
// https://github.com/github/fetch/issues/175#issuecomment-125779262
function timeoutPromise(ms, promise) {
return new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
reject(new Error("promise timeout"))
}, ms);
promise.then(
(res) => {
clearTimeout(timeoutId);
@Calvin-Huang
Calvin-Huang / FB-design-rules.md
Last active March 24, 2017 07:45
Facebook 在整合自家功能上存在一些公開原則,並且推出產品前會需要將完成的服務交給 Facebook 審核團隊檢查,這份文件將美術設計與產品設計者所需了解的資訊整理出來,協助參考流程與畫面設計。

Facebook 設計相關文件

Facebook 在整合自家功能上存在一些公開原則,並且推出產品前會需要將完成的服務交給 Facebook 審核團隊檢查,這份文件將美術設計與產品設計者所需了解的資訊整理出來,協助參考流程與畫面設計。

Facebook 平台政策

  • Icons 使用透明或有顏色的背景,如果 icon 需要白色背景,使用有顏色的邊界 Close Use a Transparent or Colored Background If Your Logo Has a Drop Shadow Use a Colored Background
  • Banners 不可以包含圓邊或是邊界,不能包含第三方的 Logo。
var repos = [];
var bookmarks = [];
var page = 1;
const repoList = $
.templates(
'repo-list',
{ markup: '#repo-list', templates: { repo: $.templates('#repo') } },
);
@Calvin-Huang
Calvin-Huang / redux-action-sequences-1.js
Last active September 5, 2017 19:49
Subscribe store and dispatch another actions.
store.subscribe(() => {
const action = store.getState().lastAction;
switch (action.type) {
case START_REQUEST: {
fetch('/api/v1/foo')
.then(response => response.json())
.then((data) => {
store.dispatch(receive(data));
})
@Calvin-Huang
Calvin-Huang / redux-action-sequences-2.js
Last active September 5, 2017 19:53
Handle action sequence in middleware
const middleware = (store) => {
return next => action => {
// Dispathcing action.
const returnValue = next(action);
// Action dispatched.
const state = store.getState();
switch (action.type) {
case START_REQUEST: {
@Calvin-Huang
Calvin-Huang / redux-action-sequences-3.js
Created September 5, 2017 21:10
Use redux-thunk to handle action sequences.
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers/index';
// Note: this API requires redux@>=3.1.0
const store = createStore(
rootReducer,
applyMiddleware(thunk)
);
const pingEpic = action$ =>
action$.filter(action => action.type === 'PING')
.mapTo({ type: 'PONG' });
// later...
dispatch({ type: 'PING' });
import { call, put } from 'redux-saga/effects'
export function* fetchData(action) {
try {
const data = yield call(Api.fetchUser, action.payload.url)
yield put({type: "FETCH_SUCCEEDED", data})
} catch (error) {
yield put({type: "FETCH_FAILED", error})
}
}