UNPKG

electron-event-flux

Version:

Redux store which synchronizes between instances in multiple process

41 lines (40 loc) 1.65 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); exports.StoreContext = React.createContext({ _appStore: null, stores: {}, state: {} }); var ContextProvider = exports.StoreContext.Provider; var Provider = /** @class */ (function (_super) { __extends(Provider, _super); function Provider(props) { var _this = _super.call(this, props) || this; _this.handleStateChange = function (state) { _this.setState({ state: state }); }; _this.appStore = props.appStore; _this.appStore.onDidChange(_this.handleStateChange); _this.state = { _appStore: _this.appStore, stores: _this.appStore.stores, state: _this.appStore.state, }; return _this; } Provider.prototype.render = function () { return (React.createElement(ContextProvider, { value: this.state }, React.Children.only(this.props.children))); }; return Provider; }(React.PureComponent)); exports.default = Provider;