@berish/stateful-react-connect
Version:
ReactJS connector for @berish/stateful state managment
37 lines • 1.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.classConnector = void 0;
const stateful_1 = require("@berish/stateful");
const SYMBOL_REACTION = Symbol('reaction');
function classConnector(stores, component) {
var _a, _b;
const cls = (_b = class extends component {
constructor(...args) {
super(...args);
this[_a] = null;
this.componentWillUnmount = this.componentWillUnmount.bind(this);
this.render = this.render.bind(this);
}
componentWillUnmount() {
if (this[SYMBOL_REACTION]) {
this[SYMBOL_REACTION].revoke();
this[SYMBOL_REACTION] = void 0;
}
if (super.componentWillUnmount)
super.componentWillUnmount();
}
render() {
if (!this[SYMBOL_REACTION]) {
let rendered = null;
this[SYMBOL_REACTION] = stateful_1.reaction(stores, () => (rendered = super.render && super.render()), () => this.forceUpdate());
return rendered;
}
return this[SYMBOL_REACTION].result();
}
},
_a = SYMBOL_REACTION,
_b);
return cls;
}
exports.classConnector = classConnector;
//# sourceMappingURL=classConnector.js.map
;