This file contains 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
<div ng-controller="uploadCtrl as upload"> | |
<!-- input file | |
input name can be changed to fit the server side | |
--> | |
<input type="file" name="myFile" | |
file-read | |
upload-data="upload.data", | |
preview="upload.preview", | |
validate="upload.validate.file"/> |
This file contains 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 Defer () { | |
var result = {}; | |
result.promise = new Promise(function(resolve, reject) { | |
result.resolve = resolve; | |
result.reject = reject; | |
}); | |
return result; | |
}; |
This file contains 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 Observable(init_value) { | |
var _value = init_value; | |
var subscriber = []; | |
function obs() { | |
if (arguments.length) { | |
_value = arguments[0]; | |
obs.trigger(); | |
return this; | |
} else { |
This file contains 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
//before | |
componentWillMount() { | |
this._asyncRequest = asyncLoadData() | |
.then(externalData => { | |
this._asyncRequest = null | |
this.setState({externalData}) | |
}) | |
} | |
//after |
This file contains 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
// before | |
componentWillUpdate(nextProps, nextState) { | |
if ( | |
this.state.someStatefulValue !== | |
nextState.someStatefulValue | |
) { | |
nextProps.onChange(nextState.someStatefulValue); | |
} | |
} |
This file contains 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
// before | |
componentWillReceiveProps(nextProps) { | |
if (this.props.currentRow !== nextProps.currentRow) { | |
this.setState({ | |
isScrollingDown: nextProps.currentRow > this.props.currentRow | |
}) | |
} | |
} | |
// after |
This file contains 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
componentDidUpdate(prevProps, prevState) { | |
if (this.props.reqPending !== prevProps.reqPending && !this.props.reqPending) { | |
if(!this.props.error){ | |
this.props.history.push('/next-page') | |
} | |
} | |
} |
This file contains 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 from 'react' | |
const ctx = React.createContext() | |
export const {Provider, Consumer} = ctx | |
export const withCounter = Component => props => <Consumer>{value => <Component {...props} counter={value} />}</Consumer> | |
export default ctx |
This file contains 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 from 'react' | |
import { withCounter } from './context' | |
const IncBtn = ({ counter }) => <button type='button' className='btn btn-primary btn-block' onClick={counter.inc}>+</button> | |
const CounterIncBtn = withCounter(IncBtn) | |
export default CounterIncBtn |
OlderNewer