REFACTOR to use getQueryParams as much as is sane

This commit is contained in:
Norbert de Langen 2019-04-11 09:23:28 +02:00
parent b1d7fbf9b2
commit 97d3c75fb7
3 changed files with 19 additions and 14 deletions

View File

@ -1,11 +1,11 @@
import { document } from 'global';
import qs from 'qs';
import ClientApi, { defaultDecorateStory } from './client_api';
import StoryStore, { splitPath } from './story_store';
import ConfigApi from './config_api';
import subscriptionsStore from './subscriptions_store';
import pathToId from './pathToId';
import { getQueryParams, getQueryParam } from './queryparams';
export {
ClientApi,
StoryStore,
@ -14,13 +14,6 @@ export {
defaultDecorateStory,
pathToId,
splitPath,
};
export const getQueryParams = () => {
return qs.parse(document.location.search, { ignoreQueryPrefix: true });
};
export const getQueryParam = key => {
const params = getQueryParams();
return params[key];
getQueryParams,
getQueryParam,
};

View File

@ -0,0 +1,11 @@
import { document } from 'global';
import qs from 'qs';
export const getQueryParams = () => {
return qs.parse(document.location.search, { ignoreQueryPrefix: true });
};
export const getQueryParam = key => {
const params = getQueryParams();
return params[key];
};

View File

@ -1,7 +1,7 @@
/* eslint no-underscore-dangle: 0 */
import { history, document } from 'global';
import EventEmitter from 'eventemitter3';
import qs from 'qs';
import EventEmitter from 'eventemitter3';
import memoize from 'memoizerific';
import debounce from 'lodash.debounce';
import { stripIndents } from 'common-tags';
@ -11,6 +11,7 @@ import { logger } from '@storybook/client-logger';
import { toId } from '@storybook/router/utils';
import pathToId from './pathToId';
import { getQueryParams } from './queryparams';
// TODO: these are copies from components/nav/lib
// refactor to DRY
@ -65,7 +66,7 @@ export default class StoryStore extends EventEmitter {
this.on(Events.STORY_INIT, () => {
let storyId = this.getIdOnPath();
if (!storyId) {
const query = qs.parse(document.location.search, { ignoreQueryPrefix: true });
const query = getQueryParams();
storyId = getIdFromLegacyQuery(query);
if (storyId) {
const { path, selectedKind, selectedStory, ...rest } = query;
@ -83,7 +84,7 @@ export default class StoryStore extends EventEmitter {
// NEW apis
getIdOnPath = () => {
const { id } = qs.parse(document.location.search, { ignoreQueryPrefix: true });
const { id } = getQueryParams();
return id;
};