-
-
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
Refactor knobs - no longer include all runtimes #1832
Conversation
When using knobs on a storybook for react, it should not include anything other then react code.
Codecov Report
@@ Coverage Diff @@
## release/3.3 #1832 +/- ##
===============================================
- Coverage 22.45% 22.31% -0.14%
===============================================
Files 321 324 +3
Lines 6280 6322 +42
Branches 796 787 -9
===============================================
+ Hits 1410 1411 +1
- Misses 4268 4322 +54
+ Partials 602 589 -13
Continue to review full report at Codecov.
|
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.
Great! Looks generally reasonable to me. I'm not exactly sure which of my comments are change requests and which are just discussion/suggestions, but we can figure it out.
addons/knobs/src/vue/index.js
Outdated
@@ -35,3 +41,23 @@ export const vueHandler = (channel, knobStore) => getStory => context => ({ | |||
knobStore.unsubscribe(this.setPaneKnobs); | |||
}, | |||
}); | |||
|
|||
// "Higher order component" / wrapper style API | |||
// In 3.3, this will become `withKnobs`, once our decorator API supports it. |
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.
This is 3.3? Should we handle this API migration now?
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 will delete that file with 4.0.
Let's keep this as backwards compatible as possible.
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.
OK then the comment is wrong?
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.
Also, I think the solution @tmeasday and I have in mind is backwards-compatible.
addons/knobs/README.md
Outdated
@@ -37,7 +40,7 @@ Now, write your stories with knobs. | |||
|
|||
```js | |||
import { storiesOf } from '@storybook/react'; | |||
import { withKnobs, text, boolean, number } from '@storybook/addon-knobs'; | |||
import { addonKnobs, text, boolean, number } from '@storybook/addon-knobs/dist/react'; |
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.
why did addonKnobs
come back? is this a bad merge?
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.
my bad indeed, good catch
addons/knobs/README.md
Outdated
// Knobs as dynamic variables. | ||
stories.add('as dynamic variables', () => { | ||
stories.add('as dynamic variables', withKnobsOptions(options)(() => { |
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.
Can we make this withKnobs(options)
? To make it consistent with withNotes
/ withInfo
?
OR can we make this wrapperKnobs(options)
if we are not ready to migrate the addon API?
addons/knobs/src/index.js
Outdated
} | ||
deprecate( | ||
() => {}, | ||
'Using @storybook/knobs directly is discouraged, please use @storybook/knobs/dist/{{framework}}' |
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.
Addons currently adopt the following es5 pattern for registration /register.js
:
require('./dist/register')
Can we do something analogous for frameworks?
addons/knobs/README.md
Outdated
@@ -237,6 +254,10 @@ If you feel like this addon is not performing well enough there is an option to | |||
Usage: | |||
|
|||
```js | |||
import { storiesOf } from '@storybook/react'; | |||
|
|||
const stories = storiesOf('') |
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.
???
addons/knobs/src/vue/index.js
Outdated
@@ -35,3 +41,23 @@ export const vueHandler = (channel, knobStore) => getStory => context => ({ | |||
knobStore.unsubscribe(this.setPaneKnobs); | |||
}, | |||
}); | |||
|
|||
// "Higher order component" / wrapper style API | |||
// In 3.3, this will become `withKnobs`, once our decorator API supports it. |
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.
OK then the comment is wrong?
addons/knobs/src/vue/index.js
Outdated
@@ -35,3 +41,23 @@ export const vueHandler = (channel, knobStore) => getStory => context => ({ | |||
knobStore.unsubscribe(this.setPaneKnobs); | |||
}, | |||
}); | |||
|
|||
// "Higher order component" / wrapper style API | |||
// In 3.3, this will become `withKnobs`, once our decorator API supports it. |
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.
Also, I think the solution @tmeasday and I have in mind is backwards-compatible.
addons/knobs/vue.js
Outdated
@@ -0,0 +1 @@ | |||
require('./dist/vue'); |
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.
don't we also need to export something?
addons/knobs/react.js
Outdated
@@ -0,0 +1 @@ | |||
require('./dist/react'); |
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.
don't we also need to export something?
…knobs/{{framework}} And other review comments
c87557d
to
5e74ef8
Compare
I agree with concerns by @shilman, otherwise looks good to me |
…storybook/addon-knobs directly
ca11103
to
8c23357
Compare
@tmeasday mind taking a look at this before we merge? |
Just looked at this, generally speaking looks like a very reasonable change. @shilman what was the final API change for knobs? |
This needs a TS type change - I opened a PR: DefinitelyTyped/DefinitelyTyped#22939 |
Issue: -addon knobs is getting some bad issues with the current way of switching platform-
Currently knobs is referencing all platform runtimes in
index.js
... Switching happens based on a global. Both are fairly bad practices. This PR addresses both.It's fully backwards compatible.
But it does introduce a new way for consuming the knobs module, using deep file imports for each specific platform.
What I did
How to test
I tested cra-kitchen-sink, vue-kitchen-sink, react-native-vanilla.