-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addon-Actions: Add preset and configure with parameters #9933
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from disable
not working. @tmeasday do you know the fix off the top of your head?
|
||
export const createDecorator = (actionsFn: any) => (...args: any[]) => (storyFn: () => any) => { | ||
applyEventHandlers(actionsFn, ...args) | ||
|
||
return storyFn(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createDecorator is used by the decorate
options. I'm a bit fuzzy on that use case but we have examples of it in a few examples.
@@ -1,8 +1,7 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|||
exports[`json-to-csf-compiler actions.json 1`] = ` | |||
"import { withActions } from '@storybook/addon-actions'; | |||
|
|||
" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making @tmeasday happy to see the imports go away!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a bunch of thoughts, I'm not quite sure of the exact way forward
addons/actions/README.md
Outdated
|
||
You can define action handles in a declarative way using `withActions` decorators. It accepts the same arguments as [`actions`](#multiple-actions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand this line, it doesn't seem correct ("It accepts the same arguments as [actions
]"). I realise this was here before but it doesn't seem right at all. The arguments are very much different.
|
||
export const createDecorator = (actionsFn: any) => (...args: any[]) => (storyFn: () => any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this used? I think we should drop it and just allow deprecated usage below..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It ends up getting used like this example:
Feels weird to me but maybe I'm not understanding the use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wow that's pretty weird. I suspect this is a super old usage pattern from before we had support for story-level decorators, this was the only way to apply a decorator to a single story.
I'm not sure we need to keep supporting it. WDYT @shilman?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think we should drop support for this too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't a great way to remove this without removing the ability to manipulate the event data for frameworks like html and web components.
The problem is if you use parameters then the presetDecorator will apply but it would have the customer actionFunctions that decorate
otherwise adds. We can't use parameters to supply the actionFunctions as they have to be serializable (so args v1 won't help here either).
Is there some other mechanism where we can 'configure' the decorator to use a different set of action functions? @tmeasday @shilman ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonspalmer I don't really understand what that use case is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tmeasday I'm not too sure of it either. It looks like we went out of our way to allow people to manipulate the event arguments. I'm not clear why you want that.
In React land (or some other JS component framework) if you wanted to manipulate the args of the event handler you could do this without any special support from the actions addon:
import { action } from '@storybook/addon-actions';
import Button from './button';
export default {
title: 'Button',
component: Button,
};
const clickAction = action('click');
export const first = () => (
<Button onClick={(...args) => clickAction(args[0])}>Hello World!</Button>
);
However in html or web components we can't do it in the story function. So the equivalent is:
import { decorate } from '@storybook/addon-actions';
const firstArg = decorate([args => [args[0]]]);
export const first = () => firstArg.withActions('click')(
() => `<button type="button">Hello World!</button>`;
);
If its important to support the manipulate of event args I don't think we have a great way to maintain support other than this approach. However, I could see us dropping it entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a conversation with @shilman we agreed the decorate API is YAGNI. I've removed it and updated the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explaining it to me anyway @jonspalmer, I get it now ;)
@@ -0,0 +1,90 @@ | |||
import addons from '@storybook/addons'; | |||
import { actions } from '../..'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a lot better having a test of some of the new logic. Not sure if this is the best factoring. Some prior art from the action.test. Could perhaps make it a little less verbose but...
ed3c994
to
6b4f35f
Compare
6b4f35f
to
2fcc21d
Compare
2fcc21d
to
1e2d8ea
Compare
Co-Authored-By: Tom Coleman <tom@thesnail.org>
1e2d8ea
to
195d26b
Compare
Awesome @jonspalmer!! 💯 Re: CircleCI, I think @ndelangen 's running point on this. Hopefully we can get it sorted out quickly 🤞 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
We're sponsored by CircleCI, but something is mis-configured. They are working on it to resolve this. |
Issue: #9741
What I did
Add a preset for Actions Addon
Changed Action Addon to be configured via parameters
Simplified the Server app to remove the special case actions code in favor of parameters.