Skip to content

Commit

Permalink
Fix Import / Export for non-redux apps
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Dec 2, 2016
1 parent 953b10f commit dcd346e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"redux": "^3.5.2",
"redux-devtools": "^3.3.1",
"redux-devtools-instrument": "^1.3.3",
"remotedev-app": "^0.10.0",
"remotedev-app": "^0.10.1",
"remotedev-monitor-components": "^0.0.4",
"remotedev-slider": "^1.1.1",
"remotedev-utils": "0.0.1"
Expand Down
9 changes: 9 additions & 0 deletions src/app/api/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import jsan from 'jsan';
import importState from './importState';

const listeners = {};
export const source = '@devtools-page';
Expand Down Expand Up @@ -78,6 +79,14 @@ function handleMessages(event) {
if (!message || message.source !== '@devtools-extension') return;
Object.keys(listeners).forEach(id => {
if (message.id && id !== message.id) return;
if (message.type === 'IMPORT') {
message.type = 'DISPATCH';
message.payload = {
type: 'IMPORT_STATE',
...importState(message.state, {})
};
message.state = undefined;
}
if (typeof listeners[id] === 'function') listeners[id](message);
else listeners[id].forEach(fn => { fn(message); });
});
Expand Down
3 changes: 2 additions & 1 deletion test/app/inject/enhancer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ describe('Redux enhancer', () => {
source: '@devtools-extension'
}, '*');
});
expect(message.type).toBe('IMPORT');
expect(message.type).toBe('DISPATCH');
expect(message.payload.type).toBe('IMPORT_STATE');
message = await listenMessage();
expect(message.type).toBe('STATE');
expect(window.store.getState()).toBe(2);
Expand Down

0 comments on commit dcd346e

Please sign in to comment.