@cap3/capitano-components
Version:
# <div style="color: crimson;">ALPHA DISCLAIMER</div>
60 lines • 1.7 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
class Component extends React.Component {
constructor() {
super(...arguments);
this.state = this.props.initialState || {};
this._setState = (state, callback) => {
this.setState(state, callback);
};
this._forceUpdate = (callBack) => this.forceUpdate(callBack);
}
getArgs() {
return {
state: this.state,
setState: this._setState,
forceUpdate: this._forceUpdate,
};
}
componentDidMount() {
if (this.props.didMount) {
this.props.didMount(this.getArgs());
}
}
shouldComponentUpdate(_, nextState) {
if (this.props.shouldUpdate) {
return this.props.shouldUpdate({
state: this.state,
nextState,
});
}
else {
return true;
}
}
componentWillUnmount() {
if (this.props.willUnmount) {
this.props.willUnmount({
state: this.state,
});
}
}
componentDidUpdate(_, prevState) {
if (this.props.didUpdate) {
this.props.didUpdate(Object.assign({}, this.getArgs(), { prevState }));
}
}
render() {
const { children, render } = this.props;
return children
? typeof children === "function"
? children(this.getArgs())
: children
: render
? render(this.getArgs())
: null;
}
}
exports.Component = Component;
//# sourceMappingURL=Component.js.map