mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-17 05:02:23 +08:00
Merge pull request #21367 from storybookjs/20728-fix-state-warnings
Core: Remove state deprecation warnings by default
This commit is contained in:
commit
2e64fa40ad
@ -38,6 +38,7 @@ import {
|
||||
} from '@storybook/core-events';
|
||||
import type { RouterData } from '@storybook/router';
|
||||
import type { Listener } from '@storybook/channels';
|
||||
import { deprecate } from '@storybook/client-logger';
|
||||
|
||||
import { createContext } from './context';
|
||||
import type { Options } from './store';
|
||||
@ -95,6 +96,7 @@ export type State = layout.SubState &
|
||||
globals.SubState &
|
||||
RouterData &
|
||||
API_OptionsData &
|
||||
DeprecatedState &
|
||||
Other;
|
||||
|
||||
export type API = addons.SubAPI &
|
||||
@ -112,6 +114,21 @@ export type API = addons.SubAPI &
|
||||
url.SubAPI &
|
||||
Other;
|
||||
|
||||
interface DeprecatedState {
|
||||
/**
|
||||
* @deprecated use index
|
||||
*/
|
||||
storiesHash: API_IndexHash;
|
||||
/**
|
||||
* @deprecated use previewInitialized
|
||||
*/
|
||||
storiesConfigured: boolean;
|
||||
/**
|
||||
* @deprecated use indexError
|
||||
*/
|
||||
storiesFailed?: Error;
|
||||
}
|
||||
|
||||
interface Other {
|
||||
[key: string]: any;
|
||||
}
|
||||
@ -318,7 +335,23 @@ function ManagerConsumer<P = Combo>({
|
||||
|
||||
export function useStorybookState(): State {
|
||||
const { state } = useContext(ManagerContext);
|
||||
return state;
|
||||
return {
|
||||
...state,
|
||||
|
||||
// deprecated fields for back-compat
|
||||
get storiesHash() {
|
||||
deprecate('state.storiesHash is deprecated, please use state.index');
|
||||
return this.index || {};
|
||||
},
|
||||
get storiesConfigured() {
|
||||
deprecate('state.storiesConfigured is deprecated, please use state.previewInitialized');
|
||||
return this.previewInitialized;
|
||||
},
|
||||
get storiesFailed() {
|
||||
deprecate('state.storiesFailed is deprecated, please use state.indexError');
|
||||
return this.indexError;
|
||||
},
|
||||
};
|
||||
}
|
||||
export function useStorybookApi(): API {
|
||||
const { api } = useContext(ManagerContext);
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
CURRENT_STORY_WAS_SET,
|
||||
STORY_MISSING,
|
||||
} from '@storybook/core-events';
|
||||
import { deprecate, logger } from '@storybook/client-logger';
|
||||
import { logger } from '@storybook/client-logger';
|
||||
|
||||
import type {
|
||||
StoryId,
|
||||
@ -56,19 +56,6 @@ type StoryUpdate = Pick<API_StoryEntry, 'parameters' | 'initialArgs' | 'argTypes
|
||||
export interface SubState extends API_LoadedRefData {
|
||||
storyId: StoryId;
|
||||
viewMode: ViewMode;
|
||||
|
||||
/**
|
||||
* @deprecated use index
|
||||
*/
|
||||
storiesHash: API_IndexHash;
|
||||
/**
|
||||
* @deprecated use previewInitialized
|
||||
*/
|
||||
storiesConfigured: boolean;
|
||||
/**
|
||||
* @deprecated use indexError
|
||||
*/
|
||||
storiesFailed?: Error;
|
||||
}
|
||||
|
||||
export interface SubAPI {
|
||||
@ -544,20 +531,6 @@ export const init: ModuleFn<SubAPI, SubState, true> = ({
|
||||
viewMode: initialViewMode,
|
||||
hasCalledSetOptions: false,
|
||||
previewInitialized: false,
|
||||
|
||||
// deprecated fields for back-compat
|
||||
get storiesHash() {
|
||||
deprecate('state.storiesHash is deprecated, please use state.index');
|
||||
return this.index || {};
|
||||
},
|
||||
get storiesConfigured() {
|
||||
deprecate('state.storiesConfigured is deprecated, please use state.previewInitialized');
|
||||
return this.previewInitialized;
|
||||
},
|
||||
get storiesFailed() {
|
||||
deprecate('state.storiesFailed is deprecated, please use state.indexError');
|
||||
return this.indexError;
|
||||
},
|
||||
},
|
||||
init: initModule,
|
||||
};
|
||||
|
@ -85,10 +85,6 @@ function createMockStore(initialState = {}) {
|
||||
function initStoriesAndSetState({ store, ...options }: any) {
|
||||
const { state, ...result } = initStories({ store, ...options } as any);
|
||||
|
||||
// Remove deprecated fields (which would trigger warnings)
|
||||
delete state.storiesHash;
|
||||
delete state.storiesConfigured;
|
||||
delete state.storiesFailed;
|
||||
store?.setState(state);
|
||||
|
||||
return { state, ...result };
|
||||
@ -120,11 +116,6 @@ describe('stories API', () => {
|
||||
viewMode: 'story',
|
||||
} as ModuleArgs);
|
||||
|
||||
// Remove deprecated fields (which would trigger warnings)
|
||||
delete state.storiesHash;
|
||||
delete state.storiesConfigured;
|
||||
delete state.storiesFailed;
|
||||
|
||||
expect(state).toEqual({
|
||||
previewInitialized: false,
|
||||
storyId: 'id',
|
||||
|
Loading…
x
Reference in New Issue
Block a user