-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3133 from rhalff/addon-actions
Addon actions: fix slow logging
- Loading branch information
Showing
18 changed files
with
279 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { action, configureActions, decorateAction } from './preview'; | ||
|
||
// addons, panels and events get unique names using a prefix | ||
export const ADDON_ID = 'storybook/actions'; | ||
export const PANEL_ID = `${ADDON_ID}/actions-panel`; | ||
export const EVENT_ID = `${ADDON_ID}/action-event`; | ||
|
||
export { action, decorateAction } from './preview'; | ||
export { action, configureActions, decorateAction }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const DEPTH_KEY = '$___storybook.depthKey'; | ||
|
||
export default function configureDepth(obj, depth = 0) { | ||
obj[DEPTH_KEY] = depth; // eslint-disable-line no-param-reassign | ||
|
||
return obj; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function omitProperty(name) { | ||
return name.startsWith('__') || name.startsWith('STORYBOOK_'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import addons from '@storybook/addons'; | ||
import { action, configureActions } from '../../'; | ||
|
||
jest.mock('@storybook/addons'); | ||
|
||
const getChannelData = channel => | ||
channel.emit.mock.calls[channel.emit.mock.calls.length - 1][1].data; | ||
|
||
describe('Action', () => { | ||
const channel = { emit: jest.fn() }; | ||
addons.getChannel.mockReturnValue(channel); | ||
|
||
it('with one argument', () => { | ||
action('test-action')('one'); | ||
|
||
expect(getChannelData(channel).args[0]).toEqual('"one"'); | ||
}); | ||
|
||
it('with multiple arguments', () => { | ||
action('test-action')('one', 'two', 'three'); | ||
|
||
expect(getChannelData(channel).args).toEqual(['"one"', '"two"', '"three"']); | ||
}); | ||
|
||
it('with global depth configuration', () => { | ||
const depth = 1; | ||
|
||
configureActions({ | ||
depth, | ||
}); | ||
|
||
action('test-action')({ | ||
root: { | ||
one: { | ||
two: 'foo', | ||
}, | ||
}, | ||
}); | ||
|
||
expect(getChannelData(channel).args[0]).toEqual( | ||
JSON.stringify({ | ||
'$___storybook.objectName': 'Object', | ||
root: { | ||
'$___storybook.objectName': 'Object', | ||
one: { | ||
'$___storybook.objectName': 'Object', | ||
}, | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
it('per action depth option overrides global config', () => { | ||
configureActions({ | ||
depth: 1, | ||
}); | ||
|
||
action('test-action', { depth: 3 })({ | ||
root: { | ||
one: { | ||
two: { | ||
three: { | ||
four: { | ||
five: 'foo', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
expect(getChannelData(channel).args[0]).toEqual( | ||
JSON.stringify({ | ||
'$___storybook.objectName': 'Object', | ||
root: { | ||
'$___storybook.objectName': 'Object', | ||
one: { | ||
'$___storybook.objectName': 'Object', | ||
two: { | ||
'$___storybook.objectName': 'Object', | ||
three: { | ||
'$___storybook.objectName': 'Object', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
addons/actions/src/preview/__tests__/configureActions.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { config } from '../configureActions'; | ||
import { configureActions } from '../../'; | ||
|
||
describe('Configure Actions', () => { | ||
it('can configure actions', () => { | ||
const depth = 100; | ||
|
||
configureActions({ | ||
depth, | ||
}); | ||
|
||
expect(config).toEqual({ | ||
depth, | ||
}); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
addons/actions/src/preview.test.js → ...ons/src/preview/__tests__/preview.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const config = { | ||
depth: 10, | ||
}; | ||
|
||
export function configureActions(options = {}) { | ||
Object.assign(config, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { action } from '../preview'; | ||
|
||
export default function decorateAction(decorators) { | ||
return (name, options) => { | ||
const callAction = action(name, options); | ||
return (..._args) => { | ||
const decorated = decorators.reduce((args, fn) => fn(args), _args); | ||
callAction(...decorated); | ||
}; | ||
}; | ||
} |
Oops, something went wrong.