功能比较简单,从URL中获取到q参数并且显示在文本框中,但允许文本框内用户输入其它的搜索词
如果让Input工作在受控模式下,那么就必须控制value的同步,也需要componentWillReceiveProps进行同步,代码较多。如果使用defaultValue但不提供key,则会导致URL变化后文本框内容不会更新
一个简易的方法就是使用key来在URL变化时强制刷新文本框,但同时也能利用defaultValue简化同步
| 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+') |
功能比较简单,从URL中获取到q参数并且显示在文本框中,但允许文本框内用户输入其它的搜索词
如果让Input工作在受控模式下,那么就必须控制value的同步,也需要componentWillReceiveProps进行同步,代码较多。如果使用defaultValue但不提供key,则会导致URL变化后文本框内容不会更新
一个简易的方法就是使用key来在URL变化时强制刷新文本框,但同时也能利用defaultValue简化同步
| /** | |
| * @file 为一个组件提供初始化时异步获取数据的能力 | |
| * @author zhanglili | |
| */ | |
| import {PureComponent, createElement} from 'react'; | |
| import {zipObject, identity, noop} from 'lodash'; | |
| import {wrapDisplayName} from 'recompose'; | |
| /** |
| 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'; |
| [ | |
| { | |
| "type": "comment", | |
| "text": "/***************************************************************************" | |
| }, | |
| { | |
| "type": "lineBreak" | |
| }, | |
| { | |
| "type": "comment", |
| // HOC版本 | |
| const withDelayHint = (loadingPropName, delay) => ComponentIn => class extends Component { | |
| state = { | |
| timer: null, | |
| isDelayed: false | |
| }; | |
| tryStartTimer = () => { | |
| clearTimeout(this.state.timer); |
| 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( |
首先建立一个新的目录,并使用yarn init进行初始化:
mkdir hello-world
yarn init -y然后安装reskript:
| 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: [ | |
| [ |
| "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) { |