Skip to content

Commit 12e4fe2

Browse files
committed
Update API
1 parent 7386ade commit 12e4fe2

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Diff for: src/app/api/index.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ export function sendMessage(action, state, shouldStringify, id) {
5555
if (action) {
5656
message.type = 'ACTION';
5757
message.action = action.action ? action :
58-
{ type: 'PERFORM_ACTION', action: typeof action === 'object' ? action : { type: action } };
59-
message.action.timestamp = Date.now();
58+
{ action: typeof action === 'object' ? action : { type: action } };
6059
} else {
6160
message.type = 'STATE';
6261
}
@@ -107,14 +106,22 @@ export function connect(config = {}) {
107106
sendMessage(action, state, config.shouldStringify, id);
108107
};
109108

110-
const init = (state) => {
109+
const init = (state, action) => {
111110
const name = config.name || document.title;
112111
toContentScript(
113-
{ type: 'INIT', payload: state, action: { timestamp: Date.now() }, id, name, source },
112+
{
113+
type: 'INIT', payload: state,
114+
action: action || {},
115+
id, name, source
116+
},
114117
config.shouldStringify
115118
);
116119
};
117120

121+
const error = (payload) => {
122+
post({ type: 'ERROR', payload, id, source });
123+
};
124+
118125
window.addEventListener('message', handleMessages, false);
119126

120127
toContentScript({ type: 'INIT_INSTANCE', id, source});
@@ -123,7 +130,8 @@ export function connect(config = {}) {
123130
init,
124131
subscribe,
125132
unsubscribe,
126-
send
133+
send,
134+
error
127135
};
128136
}
129137

Diff for: src/browser/extension/window/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ chrome.runtime.getBackgroundPage(({ store }) => {
4141
store.liftedStore.dispatch(action, currentInstance);
4242
if (action.type === 'JUMP_TO_STATE' || action.type === 'SWEEP') update();
4343
},
44+
importState: (state) => store.liftedStore.importState(state, currentInstance),
4445
subscribe
4546
},
47+
dispatch: (action) => store.dispatch(action, currentInstance),
4648
getActionCreators: () => store.getActionCreators(currentInstance),
49+
isRedux: () => store.isRedux(currentInstance),
4750
setInstance: instance => {
4851
currentInstance = instance;
4952
currentState = undefined;

Diff for: test/app/inject/api.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('API', () => {
6262
name: '',
6363
source: '@devtools-page'
6464
});
65-
expect(message.action).toInclude('{"type":"PERFORM_ACTION","action":{"type":"hi"},"timestamp"');
65+
expect(message.action).toBe('{"action":{"type":"hi"}}');
6666

6767
message = await listenMessage(() => {
6868
window.devToolsExtension.send(undefined, { counter: 1 }, false, 1);

0 commit comments

Comments
 (0)