@platform/react.ssr
Version:
A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.
65 lines (64 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var rxjs_1 = require("rxjs");
var operators_1 = require("rxjs/operators");
var common_1 = require("../common");
var Main = (function (_super) {
tslib_1.__extends(Main, _super);
function Main(props) {
var _this = _super.call(this, props) || this;
_this.state = {};
_this.state$ = new rxjs_1.Subject();
_this.unmounted$ = new rxjs_1.Subject();
_this.handleClick = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var foo, Foo, el;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
this.state$.next({ count: this.count + 1 });
foo = Promise.resolve().then(function () { return require('./Foo'); });
return [4, foo];
case 1:
Foo = _a.sent();
el = React.createElement(Foo.Foo, null);
this.state$.next({ foo: el });
return [2];
}
});
}); };
var state$ = _this.state$.pipe(operators_1.takeUntil(_this.unmounted$));
state$.subscribe(function (e) { return _this.setState(e); });
return _this;
}
Main.prototype.componentWillUnmount = function () {
this.unmounted$.next();
this.unmounted$.complete();
};
Object.defineProperty(Main.prototype, "count", {
get: function () {
return this.state.count || 0;
},
enumerable: true,
configurable: true
});
Main.prototype.render = function () {
var styles = {
base: common_1.css({
fontSize: 34,
PaddingX: 50,
PaddingY: 20,
}),
image: common_1.css({ borderRadius: 8 }),
};
return (React.createElement("div", tslib_1.__assign({}, common_1.css(styles.base, this.props.style), { onClick: this.handleClick }),
React.createElement("div", null,
"kitty: ",
this.count || 0),
React.createElement("img", tslib_1.__assign({ src: '/images/cat.jpg' }, styles.image)),
this.state.foo));
};
return Main;
}(React.PureComponent));
exports.Main = Main;