1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var React = require("react");
|
17 | var _a = React.createContext(undefined), Provider = _a.Provider, Consumer = _a.Consumer;
|
18 | var StoreProvider = (function (_super) {
|
19 | __extends(StoreProvider, _super);
|
20 | function StoreProvider() {
|
21 | return _super !== null && _super.apply(this, arguments) || this;
|
22 | }
|
23 | StoreProvider.prototype.render = function () {
|
24 | return React.createElement(Provider, { value: this.props.store }, this.props.children);
|
25 | };
|
26 | return StoreProvider;
|
27 | }(React.Component));
|
28 | exports.StoreProvider = StoreProvider;
|
29 | exports.StoreConsumer = Consumer;
|
30 | var StoreSlice = (function (_super) {
|
31 | __extends(StoreSlice, _super);
|
32 | function StoreSlice() {
|
33 | return _super !== null && _super.apply(this, arguments) || this;
|
34 | }
|
35 | StoreSlice.prototype.componentWillUnmount = function () {
|
36 | this.slice.destroy();
|
37 | };
|
38 | StoreSlice.prototype.render = function () {
|
39 | var _this = this;
|
40 | return React.createElement(Consumer, null, function (store) {
|
41 | if (!store)
|
42 | throw new Error("StoreSlice used outside of a Store context. Did forget to add a <StoreProvider>?");
|
43 |
|
44 |
|
45 |
|
46 | if (_this.slice === undefined) {
|
47 | _this.slice = store.createSlice(_this.props.slice(store), _this.props.initialState, _this.props.cleanupState);
|
48 | }
|
49 | return React.createElement(Provider, { value: _this.slice }, _this.props.children);
|
50 | });
|
51 | };
|
52 | return StoreSlice;
|
53 | }(React.Component));
|
54 | exports.StoreSlice = StoreSlice;
|
55 | exports.StoreProjection = (function (_super) {
|
56 | __extends(StoreProjection, _super);
|
57 | function StoreProjection() {
|
58 | return _super !== null && _super.apply(this, arguments) || this;
|
59 | }
|
60 | StoreProjection.prototype.componentWillUnmount = function () {
|
61 | this.slice.destroy();
|
62 | };
|
63 | StoreProjection.prototype.render = function () {
|
64 | var _this = this;
|
65 | return React.createElement(Consumer, null, function (store) {
|
66 | if (!store)
|
67 | throw new Error("StoreProjection/Slice used outside of a Store context. Did forget to add a <StoreProvider>?");
|
68 |
|
69 |
|
70 |
|
71 | if (_this.slice === undefined) {
|
72 | _this.slice = store.createProjection(_this.props.forwardProjection, _this.props.backwardProjection, _this.props.initial, _this.props.cleanup);
|
73 | }
|
74 | return React.createElement(Provider, { value: _this.slice }, _this.props.children);
|
75 | });
|
76 | };
|
77 | return StoreProjection;
|
78 | }(React.Component));
|
79 | var WithStore = (function (_super) {
|
80 | __extends(WithStore, _super);
|
81 | function WithStore() {
|
82 | return _super !== null && _super.apply(this, arguments) || this;
|
83 | }
|
84 | WithStore.prototype.render = function () {
|
85 | var _this = this;
|
86 | return React.createElement(Consumer, null, function (store) {
|
87 | var child = _this.props.children;
|
88 | if (!store)
|
89 | throw new Error("WithStore used but no store could be found in context. Did you suppliy a StoreProvider?");
|
90 | else if (typeof _this.props.children !== "function")
|
91 | throw new Error("WithStore used but its child is not a function.");
|
92 | else
|
93 | return child(store);
|
94 | });
|
95 | };
|
96 | return WithStore;
|
97 | }(React.Component));
|
98 | exports.WithStore = WithStore;
|
99 |
|
\ | No newline at end of file |