Skip to content

Instantly share code, notes, and snippets.

Gray Zhang otakustay

Block or report user

Report or block otakustay

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View unidiff.js
"use strict";
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
!function (e, n) {
"object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module ? n(exports) : "function" == typeof define && define.amd ? define(["exports"], n) : n(e.unidiff = {});
}(void 0, function (e) {
"use strict";
function n(e) {
@otakustay
otakustay / rollup.js
Created May 20, 2019
svg icon rollup
View rollup.js
const {rollup} = require('rollup');
const babel = require('rollup-plugin-babel');
const svgToReact = require('rollup-plugin-svg-to-jsx');
const autoExternal = require('rollup-plugin-auto-external');
const resolve = require('rollup-plugin-node-resolve');
const css = require('rollup-plugin-postcss');
const babelConfig = {
presets: [
[
@otakustay
otakustay / quick-start.md
Created Mar 25, 2019
reskript quick start
View quick-start.md

首先建立一个新的目录,并使用yarn init进行初始化:

mkdir hello-world
yarn init -y

然后安装reskript

@otakustay
otakustay / upgrade.js
Created Mar 15, 2019
Upgrade to reskript
View upgrade.js
const path = require('path');
const fs = require('fs');
const {execSync} = require('child_process');
const {sync: rimraf} = require('rimraf');
const {sync: glob} = require('glob');
const {mapValues} = require('lodash');
const topLevelModuleNames = glob('src/*/').map(path => path.slice(4, -1));
const replaceImportAlias = content => topLevelModuleNames.reduce(
@otakustay
otakustay / hoc.jsx
Last active Feb 13, 2019
Convert HOC to Hook
View hoc.jsx
// HOC版本
const withDelayHint = (loadingPropName, delay) => ComponentIn => class extends Component {
state = {
timer: null,
isDelayed: false
};
tryStartTimer = () => {
clearTimeout(this.state.timer);
@otakustay
otakustay / syntax-token.json
Last active Jul 13, 2018
Syntax highlight
View syntax-token.json
[
{
"type": "comment",
"text": "/***************************************************************************"
},
{
"type": "lineBreak"
},
{
"type": "comment",
@otakustay
otakustay / Diff.js
Created Mar 9, 2018
state management in react
View Diff.js
import {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {createSelector} from 'reselect';
import {parseDiff, addStubHunk, expandFromRawCode, Diff, Hunk} from 'react-diff-view';
import {push} from 'san-update/fp';
import {diffLines, formatLines} from 'unidiff';
import {property} from 'lodash/fp';
import 'react-diff-view/index.css';
import HunkHeader from './HunkHeader';
View requireFetch.js
/**
* @file 为一个组件提供初始化时异步获取数据的能力
* @author zhanglili
*/
import {PureComponent, createElement} from 'react';
import {zipObject, identity, noop} from 'lodash';
import {wrapDisplayName} from 'recompose';
/**
@otakustay
otakustay / README.md
Created Nov 13, 2017
Usage of key in react
View README.md

功能比较简单,从URL中获取到q参数并且显示在文本框中,但允许文本框内用户输入其它的搜索词

如果让Input工作在受控模式下,那么就必须控制value的同步,也需要componentWillReceiveProps进行同步,代码较多。如果使用defaultValue但不提供key,则会导致URL变化后文本框内容不会更新

一个简易的方法就是使用key来在URL变化时强制刷新文本框,但同时也能利用defaultValue简化同步

View router.js
const pathToRegExp = require('path-to-regexp');
const repo = {
index: pathToRegExp('/repos/:organization/:dir/:name'),
blob: pathToRegExp('/repos/:organization/:dir/:name/blob/:path+')
};
const legacyRepo = {
index: pathToRegExp('/repos/:organization/:dir/:name/:extra+'),
blob: pathToRegExp('/repos/:organization/:dir/:name/:extra+/blob/:path+')
You can’t perform that action at this time.