Skip to content

Commit

Permalink
attempting to pass extension id
Browse files Browse the repository at this point in the history
  • Loading branch information
godd9170 committed Jan 17, 2017
1 parent a0db4d3 commit 60f3ef0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/store/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class Store {
* Creates a new Proxy store
* @param {object} options An object of form {portName, state}, where `portName` is a required string and defines the name of the port for state transition changes and `state` is the initial state of this store (default `{}`)
*/
constructor({portName, state = {}}) {
constructor(extensionId, {portName, state = {}}) {
if (!portName) {
throw new Error('portName is required in options');
}

this.port = chrome.runtime.connect({name: portName});
this.extensionId = extensionId; //keep the extensionId as an instance variable
this.port = chrome.runtime.connect(this.extensionId, {name: portName});
this.listeners = [];
this.state = state;

Expand All @@ -24,6 +24,8 @@ class Store {
this.replaceState(message.payload);
}
});

this.dispatch = this.dispatch.bind(this); //add this context to dispatch
}

/**
Expand Down Expand Up @@ -64,10 +66,13 @@ class Store {
*/
dispatch(data) {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({
chrome.runtime.sendMessage(
this.extensionId,
{
type: DISPATCH_TYPE,
payload: data
}, ({error, value}) => {
//console.log('Error: ', error);
if (error) {
reject(assignIn((new Error()), error));
} else {
Expand Down

0 comments on commit 60f3ef0

Please sign in to comment.