- 弹框, 使用 react-modal
- tooltip 或者 popover ,使用 react-popper 或者基于 popperjs 自己鲁一个;
- setState 统一使用 react-values 或者 react-powerplug
- tab 组件,使用 react-tabs
- 日期组件
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
export default class Table extends Component { | |
render() { | |
const { keyMapper, records, ...rest } = this.props; | |
return ( | |
<table {...rest}> | |
<thead> | |
<tr> | |
{/* 渲染头部 */} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.ruanyifeng.com/blog/clipboard/ | |
var as = $('.module-list').querySelectorAll('a') | |
as = [].slice.call(as) | |
as = as.map(el => el.href) | |
var obj = {} | |
as.reduce((promise, item) => { | |
return promise.then(() => { | |
return fetch(item).then(res => res.text()).then(res => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getNewState(getState, isOriginal) { | |
const state = getState(); | |
return isOriginal ? state : object.assign({}, state); | |
} | |
function createThunkMiddleware(extraArgument, errorHandler) { | |
return ({ dispatch, getState }) => next => action => { | |
if (typeof action === 'function') { | |
const result = action(dispatch, (isOriginal) => getNewState(getState, isOriginal), extraArgument); | |
if (errorHandler && result.catch) result.catch(errorHandler); | |
return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const p = require('polka')(); | |
const debounce = require('lodash/debounce'); | |
p.get('/', (req, res) => { | |
res.end('hello world') | |
}) | |
const maxConnections = 10*10000; | |
const todos = ['hello']; | |
const users = Object.create(null); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function swap(arr, i, j) { | |
[arr[i], arr[j]] = [arr[j], arr[i]] | |
} | |
function quickSort(arr, low, high) { | |
let i, last; | |
if (low < high) { | |
last = low; | |
for (i = low + 1; i <= high; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var piexif = require('piexif'); | |
/* usage: | |
downloadPictureWithEXIFandRename('https://images.unsplash.com/photo-1502120492606-fba13cc63721?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=289f912c1f9e61361e64ac022a2a6ccc&auto=format&fit=crop&w=668&q=80', 'hello!') | |
*/ | |
function downloadPictureWithEXIFandRename(pictureUrl, pictureName, callback) { | |
var xhr = new XMLHttpRequest(); | |
var a = document.createElement('a'); | |
xhr.responseType = "arraybuffer"; | |
xhr.open('GET', pictureUrl, true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* usage | |
* | |
* componentDidMount() { | |
* likefetch('www.example.com/api/', {method: 'post', body: JSON.stringify({data: 123})}, c => this.xhr = c) | |
* } | |
* componentWillUnmount() { | |
* this.xhr && this.xhr.abort() | |
* } | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mitt(all) { | |
all = all || Object.create(null) | |
return { | |
on(type, cb){ | |
(all[type] || (all[type] = [])).push(cb); | |
}, | |
off(type, cb){ | |
if (all[type]) { | |
all[type].splice(all[type].indexOf(cb) >>> 0, 1); | |
} |
NewerOlder