Core: Dedupe default ArgTypes enhancers

This commit is contained in:
Michael Shilman 2020-11-06 06:32:32 +08:00
parent e851f4a683
commit 6f4b42595c
2 changed files with 22 additions and 3 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable no-underscore-dangle */
import createChannel from '@storybook/channel-postmessage';
import { toId } from '@storybook/csf';
import addons, { mockChannel } from '@storybook/addons';
@ -705,6 +706,23 @@ describe('preview.story_store', () => {
);
expect(store.getRawStory('a', '1').parameters.argTypes).toEqual({ e: 'f', c: 'd' });
});
it('adds user and default enhancers', () => {
const store = new StoryStore({ channel });
expect(store._argTypesEnhancers.length).toBe(1);
const enhancer = () => ({});
store.addArgTypesEnhancer(enhancer);
expect(store._argTypesEnhancers.length).toBe(2);
store.startConfiguring();
expect(store._argTypesEnhancers.length).toBe(4);
addStoryToStore(store, 'a', '1', () => 0);
addStoryToStore(store, 'a', '2', () => 0);
store.finishConfiguring();
expect(store._argTypesEnhancers.length).toBe(4);
});
});
describe('selection specifiers', () => {

View File

@ -165,6 +165,10 @@ export default class StoryStore {
startConfiguring() {
this._configuring = true;
// run these at the end
this._argTypesEnhancers.push(inferArgTypes);
this._argTypesEnhancers.push(inferControls);
}
storeGlobals() {
@ -386,9 +390,6 @@ export default class StoryStore {
const { passArgsFirst = true } = combinedParameters;
const __isArgsStory = passArgsFirst && original.length > 0;
// run at the end
this._argTypesEnhancers.push(inferArgTypes);
this._argTypesEnhancers.push(inferControls);
const { argTypes = {} } = this._argTypesEnhancers.reduce(
(accumulatedParameters: Parameters, enhancer) => ({
...accumulatedParameters,