1 | "use strict";
|
2 | var __assign = (this && this.__assign) || function () {
|
3 | __assign = Object.assign || function(t) {
|
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5 | s = arguments[i];
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7 | t[p] = s[p];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | return __assign.apply(this, arguments);
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | exports.enableDevTool = void 0;
|
15 | var redux_1 = require("redux");
|
16 | var rxjs_1 = require("rxjs");
|
17 | var operators_1 = require("rxjs/operators");
|
18 | function enableDevTool(store) {
|
19 | console.warn("enableDevTool requires the browser extension. Note: the 'skip action' feature is not supported (but 'jump' works as expected')");
|
20 | if (typeof window === "undefined") {
|
21 |
|
22 | return;
|
23 | }
|
24 | var extension = window["__REDUX_DEVTOOLS_EXTENSION__"] || window["devToolsExtension"];
|
25 | if (!extension) {
|
26 | console.warn("devToolsExtension not found in window (extension not installed?). Could not enable devTool");
|
27 | return;
|
28 | }
|
29 | var devtoolExtension = extension();
|
30 | var reduxToReactiveSync = new rxjs_1.Subject();
|
31 | var reactiveStateUpdate = new rxjs_1.Subject();
|
32 | store
|
33 | .select()
|
34 | .pipe(operators_1.take(1))
|
35 | .subscribe(function (initialState) {
|
36 | var enhancer = function (next) {
|
37 | return function (reducer, preloadedState) {
|
38 |
|
39 | var reduxStore = next(reducer, initialState);
|
40 |
|
41 | reduxStore.subscribe(function () {
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | });
|
47 | reactiveStateUpdate.subscribe(function (p) {
|
48 |
|
49 | reduxStore.dispatch({ type: p.actionName, payload: p.payload, state: p.state });
|
50 | });
|
51 | return reduxStore;
|
52 | };
|
53 | };
|
54 |
|
55 |
|
56 | var reduxReducer = function (state, action) {
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | if (action.type === "@@INIT") {
|
62 |
|
63 | return __assign({}, state);
|
64 | }
|
65 |
|
66 |
|
67 | return __assign({}, action.state);
|
68 | };
|
69 | redux_1.createStore(reduxReducer, initialState, redux_1.compose(enhancer, devtoolExtension));
|
70 | });
|
71 | store.stateChangedNotification.subscribe(function (notification) {
|
72 | var actionName = notification.actionName, actionPayload = notification.actionPayload, newState = notification.newState;
|
73 | if (actionName !== "__INTERNAL_SYNC")
|
74 | reactiveStateUpdate.next({ actionName: actionName || "UNNAMED", payload: actionPayload, state: newState });
|
75 | });
|
76 | var syncReducer = function (state, payload) {
|
77 | return __assign({}, payload);
|
78 | };
|
79 | store.addReducer(reduxToReactiveSync, syncReducer, "__INTERNAL_SYNC");
|
80 | }
|
81 | exports.enableDevTool = enableDevTool;
|
82 |
|
\ | No newline at end of file |