export default function (provider, reduxStore, actions) {
  const providerApi = {
    onStory(cb) {
      providerApi._onStoryCallback = cb;
    },

    addAction: actions.api.addAction,
    setStories: actions.api.setStories,
    selectStory: actions.api.selectStory,
    handleShortcut: actions.shortcuts.handleEvent,
  };

  provider.handleAPI(providerApi);

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

    providerApi._onStoryCallback(api.selectedKind, api.selectedStory);
  });
}

export default function (provider, reduxStore, actions) {
  const providerApi = {
    onStory(cb) {
      providerApi._onStoryCallback = cb;
    },

    addAction: actions.api.addAction,
    setStories: actions.api.setStories,
    selectStory: actions.api.selectStory,
    handleShortcut: actions.shortcuts.handleEvent,
  };

  provider.handleAPI(providerApi);

  // subscribe to redux store and trigger onStory's callback
  reduxStore.subscribe(function () {
    const { api } = reduxStore.getState();
    if (!api) return;
    if (!providerApi._onStoryCallback) return;
    
    providerApi._onStoryCallback(api.selectedKind, api.selectedStory);
  });
}

Make sure api.onStory has been called or not.
Make sure api.onStory has been called or not.
