mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
REFACTOR to use getQueryParams as much as is sane
This commit is contained in:
parent
b1d7fbf9b2
commit
97d3c75fb7
@ -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,
|
||||
};
|
||||
|
11
lib/client-api/src/queryparams.js
Normal file
11
lib/client-api/src/queryparams.js
Normal 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];
|
||||
};
|
@ -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;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user