Skip to content
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 framework-independent core library #2241

Merged
merged 9 commits into from
Jan 3, 2018
Merged

Conversation

shilman
Copy link
Member

@shilman shilman commented Nov 6, 2017

Issue: #2240

What I did

Work in progress: first proof of concept for discussion

  • create @storybook/core library
  • move most common code into library
  • add some per-framework configuration for decorators

Still to-do:

  • Update RN
  • Refactor RN more aggressively
  • Refactor manager code
  • Refactor server code
  • Update tests/docs

How to test

yarn bootstrap --core
cd examples/cra-kitchen-sink
yarn storybook
cd ../vue-kitchen-sink
yarn storybook
cd ../angular-cli
yarn storybook
cd ../..
yarn test

Is this testable with jest or storyshots?

Does this need a new example in the kitchen sink apps?

Does this need an update to the documentation?

If your answer is yes to any of these, please make sure to include it in your PR.

Questionable changes:
- ability to pass a story decorator function
- pass clearDecorators to ConfigAPI

React/Vue/Angular working (apparently). RN still broken.
@shilman shilman requested review from tmeasday and a team November 6, 2017 11:21
@danielduan
Copy link
Member

Is the plan to move most of the server stuff over as well or should that be a separate package?

@@ -1,11 +1,11 @@
import keyEvents from '@storybook/ui/dist/libs/key_events';
import { selectStory } from './actions';
import { Actions } from '@storybook/core/client';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would exporting & importing all actions individually be better here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to bundle them to keep the namespace smaller. Open to counter-arguments.

@@ -0,0 +1,13 @@
# Storybook for React

[![Greenkeeper badge](https://badges.greenkeeper.io/storybooks/storybook.svg)](https://greenkeeper.io/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated readme

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, though somehow it's not showing up here. Still need to write the actual contents and it's in the TODO list at top of PR.

@tmeasday
Copy link
Member

tmeasday commented Nov 8, 2017

Some ideas on how we could improve this further:

- resolve conflicts
- fix RN story_store (make it an EventEmitter)
@codecov
Copy link

codecov bot commented Nov 8, 2017

Codecov Report

Merging #2241 into release/3.3 will decrease coverage by 0.48%.
The diff coverage is 9.83%.

Impacted file tree graph

@@               Coverage Diff               @@
##           release/3.3    #2241      +/-   ##
===============================================
- Coverage        22.66%   22.18%   -0.49%     
===============================================
  Files              346      338       -8     
  Lines             6767     6587     -180     
  Branches           887      856      -31     
===============================================
- Hits              1534     1461      -73     
+ Misses            4587     4483     -104     
+ Partials           646      643       -3
Impacted Files Coverage Δ
lib/core/src/client/preview/reducer.js 0% <ø> (ø)
...react-native/src/manager/components/PreviewHelp.js 0% <ø> (ø) ⬆️
lib/components/src/highlight_button.js 0% <ø> (ø) ⬆️
lib/core/src/client/preview/actions.js 0% <ø> (ø)
app/react-native/src/preview/index.js 0% <0%> (ø) ⬆️
app/angular/src/client/preview/init.js 0% <0%> (ø) ⬆️
lib/core/src/client/preview/config_api.js 0% <0%> (ø)
lib/core/src/client/index.js 0% <0%> (ø)
lib/core/src/client/preview/index.js 0% <0%> (ø)
app/react/src/client/preview/init.js 0% <0%> (ø) ⬆️
... and 53 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 79fb667...e8f76ce. Read the comment docs.

@shilman
Copy link
Member Author

shilman commented Nov 8, 2017

@tmeasday Updated the binding per your suggestion.

I didn't factor out init.js in the first pass because it depends on the UI library and I didn't want to introduce that dependency into core. But agree that it's dupe code and should be factored out. Same with the query-string code. Open to suggestions on the API for this if you have ideas! Otherwise, will take a crack at this in the next day or two.

Thanks!

@tmeasday
Copy link
Member

tmeasday commented Nov 8, 2017

I was thinking just something like:

import { init } from '@storybook/core/web';
init(); // <- we could pass args if ever needed to

// or even just
import '@storybook/core/init-web';

@Hypnosphi
Copy link
Member

@tmeasday do you mean import '@storybook/core/init-web'?

@tmeasday
Copy link
Member

tmeasday commented Nov 8, 2017

@tmeasday do you mean import '@storybook/core/init-web'?

@Hypnosphi too fast off the mark there ;) Gotta give me time to fix my mistakes

@shilman
Copy link
Member Author

shilman commented Nov 9, 2017

@danielduan long-term will refactor everything, including preview, manager, and server. starting with preview since that's where most of the action is.

- move keyboard handling to the UI library, rather than introducing new
deps
- keep QS handling in each framework (for now)
@codecov-io
Copy link

codecov-io commented Nov 9, 2017

Codecov Report

Merging #2241 into master will decrease coverage by 13.62%.
The diff coverage is 6.74%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #2241       +/-   ##
===========================================
- Coverage   32.69%   19.07%   -13.63%     
===========================================
  Files         398      324       -74     
  Lines        8837     7666     -1171     
  Branches      967      820      -147     
===========================================
- Hits         2889     1462     -1427     
- Misses       5271     5567      +296     
+ Partials      677      637       -40
Impacted Files Coverage Δ
app/react/src/client/preview/render.js 0% <ø> (ø) ⬆️
lib/core/src/client/preview/reducer.js 0% <ø> (ø)
lib/core/src/client/preview/actions.js 0% <ø> (ø)
lib/components/src/highlight_button.js 0% <ø> (ø) ⬆️
lib/core/src/client/preview/index.js 0% <0%> (ø)
lib/core/src/client/preview/story_store.js 0% <0%> (ø)
lib/core/src/client/index.js 0% <0%> (ø)
app/react-native/src/preview/index.js 0% <0%> (ø) ⬆️
lib/core/src/client/preview/config_api.js 0% <0%> (ø)
lib/ui/src/libs/key_events.js 18.86% <0%> (-21.14%) ⬇️
... and 184 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a9d7440...9c3ec7f. Read the comment docs.

@shilman
Copy link
Member Author

shilman commented Nov 9, 2017

@tmeasday refactored init per our slack chat. will pull out the query string handling when i try to deal with the manager code. short-term was able to remove a few fields from the context object.

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@mAAdhaTTah
Copy link

mAAdhaTTah commented Nov 13, 2017

Would this make it feasible for a framework author to integrate with Storybook? Is there a plan to make that possible?

@tmeasday
Copy link
Member

@shilman -- what's up with this PR? I was looking at making some core changes but it feels weird to touch code before this PR has been merged. Are we waiting to merge it post 3.3?

@ndelangen
Copy link
Member

Yes, we are @tmeasday, maybe you can base your work on this PR, or even on this branch?

@ndelangen ndelangen changed the base branch from release/3.3 to master December 23, 2017 23:46
…factor

Use store revisions to ensure that stories re-render on HMR.
@ndelangen ndelangen merged commit 9c3ec7f into master Jan 3, 2018
@tmeasday
Copy link
Member

tmeasday commented Jan 3, 2018

Great to get this merged! Shall we open an issue to discuss the remaining refactoring candidates?

@tmeasday tmeasday deleted the shilman/refactor-core branch January 3, 2018 22:02
@ndelangen
Copy link
Member

Yes sounds good!

@tmeasday
Copy link
Member

tmeasday commented Jan 3, 2018

=> #2636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants