bot18
Version:
A high-frequency cryptocurrency trading bot by Zenbot creator @carlos8f
78 lines (60 loc) • 1.48 kB
JavaScript
'use strict';
const {enqueueUpdate} = require('./render-queue');
class Component {
constructor(props, context) {
this.props = props;
this.context = context;
this.state = {};
this._onUpdate = null;
this._pendingState = null;
this._stateUpdateCallbacks = [];
}
setState(nextState, callback) {
if (typeof nextState === 'function') {
nextState = nextState(this.state, this.props);
}
this._pendingState = Object.assign({}, this._pendingState || this.state, nextState);
if (typeof callback === 'function') {
this._stateUpdateCallbacks.push(callback);
}
this._enqueueUpdate();
}
forceUpdate() {
this._enqueueUpdate();
}
componentWillMount() {}
componentDidMount() {}
componentWillUnmount() {}
componentDidUnmount() {}
componentWillReceiveProps() {}
componentWillUpdate() {}
componentDidUpdate() {}
shouldComponentUpdate() {
return true;
}
getChildContext() {
return {};
}
render() {
return null;
}
_render() {
return this.render(this.props, this.state, this.context);
}
_componentWillUpdate(nextProps, nextState) {
this.componentWillUpdate(nextProps, nextState);
this.props = nextProps;
this.state = nextState;
this._pendingState = null;
}
_componentDidUpdate() {
this.componentDidUpdate();
this._stateUpdateCallbacks.forEach(cb => cb());
this._stateUpdateCallbacks = [];
}
_enqueueUpdate() {
enqueueUpdate(this._onUpdate);
}
}
Component.isComponent = true;
module.exports = Component;