-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Allow passing options to storiesOf().add()
as hook to customizing story behaviour in plugins
#993
Comments
Thank you @theinterned for opening this discussion One more great variant (actually something between Options 1 and 2) was offered by @nutgaard in #705
the big advantage of this is that we can pass data through addons like |
Some thoughts:
|
@tmeasday in answer to your third question, I guess the big advantages that a JSX approach gives are the same familiar advantages that all react development gives:
|
@tmeasday as to your question "doesn't the story part need to be a function: how would that work in JSX?" Can you clarify that a bit? Aren't components functions (and sometimes classes)? or do you mean something else? |
On the function part: I mean that the current interface expects to be passed a function that returns a React element (I guess equivalent to a stateless functional component). Your version above passes an element as a child to the The equivalent thing would be to pass in a prop: I'm not sure exactly why the interface is as it is, a guess is so that you get a new element each time you visit the story. |
On the general question of a "react" interface, let's unpack this a little more. I suspect you can get a lot of the advantages you've stated with a basic OO class-based interface. I'm not necessarily advocating for that, but I want to use it for comparison. So something like: new Chapter({
title: 'Chapter',
stories: [
new Story({
title: 'Story',
render() { return <My Component ... />; },
}),
}); To your points:
I'm not necessarily against it but I am trying to tease it out so bear with me. I guess I just wonder if the "rendering" interface is restrictive for little benefit. For instance, it no longer becomes easy to take an instance of a chapter and get its stories (compare the two cases: a class instance with a Is there a reason why restricting the way we think about stories to "rendering" is a good thing? I'm not sure there is. |
@tmeasday I agree that you could absolutely describe any interface that is currently described in JSX in pure JS: that's one of the fundamentaly great things about JSX: it transpiles to just pure JS, but is so much nicer to look at then a deeply nested tree of objects and arrays. So yes people are familiar with OO style and with, say, the functional style of most other testing packages (which I would sort of prefer to see somehow then the fluent api of storybooks as it stands now). But there's a certain expressiveness to the JSX syntax. I think the value of composition is well expressed by @usulpro in slack: it makes it easy to solve problems like this: #766 because the add-on could be a component rather than a plugin. |
I created a separate issue about the JSX syntax: #1006 we can continue the discussion there. I feel that the JSX syntax may be a distraction from the conversation about a generic way to pass props to |
I'm fully on board with this idea! |
Very solid proposal for #1209 api-v2 |
I'm board with |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks! |
I am working on this actually #2679! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks! |
This is done actually, just waiting to be merged in #2679. |
Released as |
Having the generic ability to pass options alongside each story to the
storiesOf
andadd
method would open the door to some easier per-story customization in decorators or other add-ons.I see few possible solutions:
Option 1: add an
options
argumentMake
options
an argument tostoriesOf
andadd
. This would look like this:Option 2: Make
storiesOf
andadd
accept a single options hash argChange the api for
storiesOf
andadd
so that they accept a single options arg. Something along the lines of:Note: Moved the JSX syntax proposal to #1006
The text was updated successfully, but these errors were encountered: