Skip to content

Commit

Permalink
Merge pull request #1 from mugi-uno/implements_auto_bind_when_page_ch…
Browse files Browse the repository at this point in the history
…anged

Implement event binding on page changed
  • Loading branch information
mugi-uno authored Oct 2, 2017
2 parents 48bbf67 + bb42b86 commit 77631ff
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/background.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/content.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/content.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/devtools.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/panel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/panel.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/content/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as devtoolMutationTypes from '../panel/store/mutation-types';

const devtoolHandler = (msg) => {
switch (msg.type) {
case devtoolMutationTypes.CONTENT_CONNECT:
case devtoolMutationTypes.PANEL_TOGGLE_WATCHING:
watcher.toggle(msg.payload);
break;
Expand Down Expand Up @@ -44,5 +45,7 @@ export default function() {
console.log('background -> content', msg);
emitter.emit('background.receive', msg);
});

emitter.emit('background.send', { type: 'connect' });
});
}
3 changes: 3 additions & 0 deletions lib/panel/store/modules/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const actions = {
};

const mutations = {
[types.CONTENT_CONNECT](state, value) {
// nothing to do.
},
[types.PANEL_TOGGLE_WATCHING](state, value) {
if (value === true || value === false) {
state.watching = value;
Expand Down
2 changes: 2 additions & 0 deletions lib/panel/store/mutation-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export const PANEL_TOGGLE_WATCHING = 'PANEL_TOGGLE_WATCHING';
export const PANEL_CLEAR = 'PANEL_CLEAR';

export const CONTENT_FIRE = 'CONTENT_FIRE';
export const CONTENT_CONNECT = 'CONTENT_CONNECT';
export const CONTENT_CONNECT_RECEIVE = 'CONTENT_CONNECT_RECEIVE';
13 changes: 10 additions & 3 deletions lib/panel/store/plugins/chromeExtention.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ export const chromeMessagingPlugin = (port) => (store) => {
store.commit(`${msg.location}_${msg.type}`.toUpperCase(), msg.value);
});

store.subscribe((mutation) => {
if (mutation.type === types.PANEL_TOGGLE_WATCHING) {
port.postMessage(mutation);
store.subscribe((mutation, state) => {
switch (mutation.type || '') {
case types.CONTENT_CONNECT:
port.postMessage(Object.assign({}, mutation, { payload: state.panel.watching }));
break;
case types.PANEL_TOGGLE_WATCHING:
port.postMessage(mutation);
break;
default:
// nothing to do;
}
});
};

0 comments on commit 77631ff

Please sign in to comment.