Skip to content

Commit

Permalink
Merge pull request #31 from kadirahq/on-story-bug-fix
Browse files Browse the repository at this point in the history
On story bug fix
  • Loading branch information
arunoda authored Aug 24, 2016
2 parents 66cb59d + bafe09d commit 7f55722
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/modules/api/configs/__tests__/init_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,14 @@ describe('manager.api.config.initApi', () => {

it('should support to add multiple onStory callback', (done) => {
const actions = { api: {}, shortcuts: {} };
const selectedKind = 'XXdd';
const selectedStory = 'u8sd';

const reduxStore = {
subscribe: sinon.stub(),
getState: () => ({ api: {} }),
getState: () => ({
api: { selectedKind, selectedStory },
}),
};

const provider = {
Expand All @@ -91,10 +95,14 @@ describe('manager.api.config.initApi', () => {

it('should support a way to remove onStory callback', (done) => {
const actions = { api: {}, shortcuts: {} };
const selectedKind = 'XXdd';
const selectedStory = 'u8sd';

const reduxStore = {
subscribe: sinon.stub(),
getState: () => ({ api: {} }),
getState: () => ({
api: { selectedKind, selectedStory },
}),
};

const provider = {
Expand Down
9 changes: 9 additions & 0 deletions src/modules/api/configs/init_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@ export default function (provider, reduxStore, actions) {
provider.handleAPI(providerApi);

// subscribe to redux store and trigger onStory's callback
let currentKind;
let currentStory;
reduxStore.subscribe(function () {
const { api } = reduxStore.getState();
if (!api) return;

if (api.selectedKind === currentKind && api.selectedStory === currentStory) {
// No change in the selected story so avoid emitting 'story'
return;
}

currentKind = api.selectedKind;
currentStory = api.selectedStory;
callbacks.emit('story', api.selectedKind, api.selectedStory);
// providerApi._onStoryCallback(api.selectedKind, api.selectedStory);
});
Expand Down

0 comments on commit 7f55722

Please sign in to comment.