UNPKG

kor-react

Version:

Utilities for consuming kor observables in React components

55 lines (54 loc) 1.89 kB
var __extends = this.__extends || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } __.prototype = b.prototype; d.prototype = new __(); }; var kor = require('kor'); var React = require('react'); function ignore() { } var Komponent = (function (_super) { __extends(Komponent, _super); function Komponent() { _super.apply(this, arguments); } Komponent.prototype._koInternals = function () { if (!this._koCachedInternals) { this._koCachedInternals = {}; } return this._koCachedInternals; }; Komponent.prototype.componentWillReceiveProps = function (nextProps) { var internals = this._koInternals(); if (internals.renderSoon) { internals.renderSoon.notifySubscribers(); } }; Komponent.prototype.componentDidMount = function () { var _this = this; var internals = this._koInternals(); if (!internals.listener) { internals.renderSoon = kor.observable(); internals.listener = kor.pureComputed(function () { internals.renderSoon(); internals.rendered = _this.renderKor(); _this.forceUpdate(); }).extend({ throttle: 1 }); } internals.subscription = internals.listener.subscribe(ignore); }; Komponent.prototype.componentWillUnmount = function () { var internals = this._koInternals(); internals.subscription.dispose(); internals.subscription = null; }; Komponent.prototype.render = function () { return this._koInternals().rendered || null; }; // Override this instead of render() Komponent.prototype.renderKor = function () { return null; }; return Komponent; })(React.Component); exports.Komponent = Komponent;