-
-
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
Migrate @storybook/core-events to TypeScript #5140
Conversation
It looks like |
I will check this later today |
So awesome to have you helping us @dandean! 👏 |
lib/core-events/src/index.ts
Outdated
STORY_THREW_EXCEPTION: string; | ||
} | ||
|
||
const events: CoreEvents = { |
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.
Do you think we can throw away the above interface if we use enum
?
Both solutions offer auto-completion in js and ts
I did
enum events {
CHANNEL_CREATED = 'channelCreated',
GET_CURRENT_STORY = 'getCurrentStory',
SET_CURRENT_STORY = 'setCurrentStory',
GET_STORIES = 'getStories',
SET_STORIES = 'setStories',
SELECT_STORY = 'selectStory',
APPLY_SHORTCUT = 'applyShortcut',
STORY_ADDED = 'storyAdded',
FORCE_RE_RENDER = 'forceReRender',
REGISTER_SUBSCRIPTION = 'registerSubscription',
STORY_RENDERED = 'storyRendered',
STORY_ERRORED = 'storyErrored',
STORY_THREW_EXCEPTION = 'storyThrewException',
}
export default events;
and it compiled to
Object.defineProperty(exports, "__esModule", { value: true });
var events;
(function (events) {
events["CHANNEL_CREATED"] = "channelCreated";
events["GET_CURRENT_STORY"] = "getCurrentStory";
events["SET_CURRENT_STORY"] = "setCurrentStory";
events["GET_STORIES"] = "getStories";
events["SET_STORIES"] = "setStories";
events["SELECT_STORY"] = "selectStory";
events["APPLY_SHORTCUT"] = "applyShortcut";
events["STORY_ADDED"] = "storyAdded";
events["FORCE_RE_RENDER"] = "forceReRender";
events["REGISTER_SUBSCRIPTION"] = "registerSubscription";
events["STORY_RENDERED"] = "storyRendered";
events["STORY_ERRORED"] = "storyErrored";
events["STORY_THREW_EXCEPTION"] = "storyThrewException";
})(events || (events = {}));
exports.default = events;
before it was
var events = {
CHANNEL_CREATED: 'channelCreated',
GET_CURRENT_STORY: 'getCurrentStory',
SET_CURRENT_STORY: 'setCurrentStory',
GET_STORIES: 'getStories',
SET_STORIES: 'setStories',
SELECT_STORY: 'selectStory',
APPLY_SHORTCUT: 'applyShortcut',
STORY_ADDED: 'storyAdded',
FORCE_RE_RENDER: 'forceReRender',
REGISTER_SUBSCRIPTION: 'registerSubscription',
STORY_RENDERED: 'storyRendered',
STORY_ERRORED: 'storyErrored',
STORY_THREW_EXCEPTION: 'storyThrewException',
};
exports.default = events;
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.
Works for me – I'll give that change a shot.
You can fix the
|
error in CI:
I get the same locally:
On my local machine, no |
@dandean I invited you to the GitHub organisation, |
# Conflicts: # yarn.lock
found a FIX I think: the prepare script was missing in This allows the DLL to build, let's see if another problem appears |
Wonderful – thank you @ndelangen. I've got the change requests from @kroeder on my TODO list today so if this builds as expected now I'll get those patches in. |
Codecov Report
@@ Coverage Diff @@
## next #5140 +/- ##
=========================================
- Coverage 35.3% 35.22% -0.09%
=========================================
Files 596 596
Lines 7378 7392 +14
Branches 1014 1010 -4
=========================================
- Hits 2605 2604 -1
- Misses 4261 4275 +14
- Partials 512 513 +1
Continue to review full report at Codecov.
|
Amazing work @dandean ! 👏 |
Thanks for your help, @kroeder and @ndelangen. |
I'm not sure I fully understand the subtlety but I want to flag that I had to make this change: 5cfd3c8 And it looks like a lot of other files use the events in similar ways. I'm not sure what needs to change but hopefully someone that has more time and context can fill me in please? |
@tmeasday Thanks for noting this. I think I understand this issue, and that it's a conflict between how the module systems operate. In the CommonJS module system (depending on how babel is configured) using That duality isn't automatically supported in the ES6 and TypeScript module systems, so I think we need to make it explicit by both exporting the I will put a PR together. |
WIP patch here: #5186 |
Issue: #5030
What I did
Migrated
@storybook/core-events
to TypeScript.Many packages depend on
@storybook/core-events
. Before migrating those packages to TypeScript it might make sense to migrate this one first. Also, this is my first contribution to this project and doing something small to get used to your process seems like the right way to go.How to test
I don't believe there is anything to test in this work. Please let me know if you'd like to see anything here.
cc @kroeder