1 | var _class, _temp;
|
2 |
|
3 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4 |
|
5 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
6 |
|
7 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
8 |
|
9 | var _require = require('@uppy/core'),
|
10 | Plugin = _require.Plugin;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | module.exports = (_temp = _class =
|
20 |
|
21 | function (_Plugin) {
|
22 | _inheritsLoose(ReduxDevTools, _Plugin);
|
23 |
|
24 | function ReduxDevTools(uppy, opts) {
|
25 | var _this;
|
26 |
|
27 | _this = _Plugin.call(this, uppy, opts) || this;
|
28 | _this.type = 'debugger';
|
29 | _this.id = _this.opts.id || 'ReduxDevTools';
|
30 | _this.title = 'Redux DevTools';
|
31 |
|
32 | var defaultOptions = {};
|
33 |
|
34 | _this.opts = _extends({}, defaultOptions, opts);
|
35 | _this.handleStateChange = _this.handleStateChange.bind(_assertThisInitialized(_this));
|
36 | _this.initDevTools = _this.initDevTools.bind(_assertThisInitialized(_this));
|
37 | return _this;
|
38 | }
|
39 |
|
40 | var _proto = ReduxDevTools.prototype;
|
41 |
|
42 | _proto.handleStateChange = function handleStateChange(prevState, nextState, patch) {
|
43 | this.devTools.send('UPPY_STATE_UPDATE', nextState);
|
44 | };
|
45 |
|
46 | _proto.initDevTools = function initDevTools() {
|
47 | var _this2 = this;
|
48 |
|
49 | this.devTools = window.devToolsExtension.connect();
|
50 | this.devToolsUnsubscribe = this.devTools.subscribe(function (message) {
|
51 | if (message.type === 'DISPATCH') {
|
52 | console.log(message.payload.type);
|
53 |
|
54 | switch (message.payload.type) {
|
55 | case 'RESET':
|
56 | _this2.uppy.reset();
|
57 |
|
58 | return;
|
59 |
|
60 | case 'IMPORT_STATE':
|
61 | {
|
62 | var computedStates = message.payload.nextLiftedState.computedStates;
|
63 | _this2.uppy.store.state = _extends({}, _this2.uppy.getState(), computedStates[computedStates.length - 1].state);
|
64 |
|
65 | _this2.uppy.updateAll(_this2.uppy.getState());
|
66 |
|
67 | return;
|
68 | }
|
69 |
|
70 | case 'JUMP_TO_STATE':
|
71 | case 'JUMP_TO_ACTION':
|
72 | _this2.uppy.store.state = _extends({}, _this2.uppy.getState(), JSON.parse(message.state));
|
73 |
|
74 | _this2.uppy.updateAll(_this2.uppy.getState());
|
75 |
|
76 | }
|
77 | }
|
78 | });
|
79 | };
|
80 |
|
81 | _proto.install = function install() {
|
82 | this.withDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__;
|
83 |
|
84 | if (this.withDevTools) {
|
85 | this.initDevTools();
|
86 | this.uppy.on('state-update', this.handleStateChange);
|
87 | }
|
88 | };
|
89 |
|
90 | _proto.uninstall = function uninstall() {
|
91 | if (this.withDevTools) {
|
92 | this.devToolsUnsubscribe();
|
93 | this.uppy.off('state-update', this.handleStateUpdate);
|
94 | }
|
95 | };
|
96 |
|
97 | return ReduxDevTools;
|
98 | }(Plugin), _class.VERSION = "1.3.1", _temp); |
\ | No newline at end of file |