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

Migrate @storybook/core-events to TypeScript #5140

Merged
merged 4 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/core-events/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"url": "https://github.com/storybooks/storybook.git"
},
"license": "MIT",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"publishConfig": {
"access": "public"
}
Expand Down
20 changes: 19 additions & 1 deletion lib/core-events/index.js → lib/core-events/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
module.exports = {
export interface CoreEvents {
CHANNEL_CREATED: string;
GET_CURRENT_STORY: string;
SET_CURRENT_STORY: string;
GET_STORIES: string;
SET_STORIES: string;
SELECT_STORY: string;
APPLY_SHORTCUT: string;
STORY_ADDED: string;
FORCE_RE_RENDER: string;
REGISTER_SUBSCRIPTION: string;
STORY_RENDERED: string;
STORY_ERRORED: string;
STORY_THREW_EXCEPTION: string;
}

const events: CoreEvents = {
Copy link
Member

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;

Copy link
Member Author

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.

CHANNEL_CREATED: 'channelCreated',
GET_CURRENT_STORY: 'getCurrentStory',
SET_CURRENT_STORY: 'setCurrentStory',
Expand All @@ -13,3 +29,5 @@ module.exports = {
STORY_ERRORED: 'storyErrored',
STORY_THREW_EXCEPTION: 'storyThrewException',
};

export default events;
8 changes: 8 additions & 0 deletions lib/core-events/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": []
}