Skip to content

Commit

Permalink
Merge pull request #8770 from aromanarguello/svelteTypescriptMigration
Browse files Browse the repository at this point in the history
Svelte: Migrate @storybook/svelte to Typescript
  • Loading branch information
shilman authored Nov 12, 2019
2 parents 3531f4f + 3c76269 commit 4f59937
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 11 deletions.
2 changes: 2 additions & 0 deletions app/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"*.d.ts"
],
"main": "dist/client/index.js",
"types": "dist/client/index.d.ts",
"bin": {
"build-storybook": "./bin/build.js",
"start-storybook": "./bin/index.js",
Expand All @@ -32,6 +33,7 @@
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "5.3.0-alpha.43",
"@storybook/core": "5.3.0-alpha.43",
"core-js": "^3.0.1",
"global": "^4.3.2",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const {
} = clientApi;

const framework = 'svelte';
export const storiesOf = (...args) => clientApi.storiesOf(...args).addParameters({ framework });
export const configure = (...args) => coreConfigure(...args, framework);
export const storiesOf = (...args: any) =>
clientApi.storiesOf(...args).addParameters({ framework });
export const configure = (...args: any) => coreConfigure(...args, framework);

export { forceReRender };
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { document } from 'global';
import dedent from 'ts-dedent';
import { MountViewArgs, RenderMainArgs } from './types';

let previousComponent = null;
type Component = any;

let previousComponent: Component = null;

function cleanUpPreviousStory() {
if (!previousComponent) {
return;
}

previousComponent.$destroy();
previousComponent = null;
}

function mountView({ Component, target, props, on, Wrapper, WrapperData }) {
let component;
function mountView({ Component, target, props, on, Wrapper, WrapperData }: MountViewArgs) {
let component: Component;

if (Wrapper) {
const fragment = document.createDocumentFragment();
Expand Down Expand Up @@ -47,8 +49,7 @@ export default function render({
selectedStory,
showMain,
showError,
// showException,
}) {
}: RenderMainArgs) {
const {
/** @type {SvelteComponent} */
Component,
Expand Down
33 changes: 33 additions & 0 deletions app/svelte/src/client/preview/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { StoryFn } from '@storybook/addons';

export interface ShowErrorArgs {
title: string;
description: string;
}

export interface RenderMainArgs {
storyFn: StoryFn<any>;
selectedKind: string;
selectedStory: string;
showMain: () => void;
showError: (args: ShowErrorArgs) => void;
}

export interface MountViewArgs {
Component: any;
target: any;
props: MountProps;
on: any;
Wrapper: any;
WrapperData: any;
}

interface MountProps {
rounded: boolean;
text: string;
}

interface WrapperData {
innerStyle: string;
style: string;
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function webpack(config) {
import { Configuration } from 'webpack'; // eslint-disable-line

export function webpack(config: Configuration) {
return {
...config,
module: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import packageJson from '../../package.json';
const packageJson = require('../../package.json');

export default {
packageJson,
Expand Down
2 changes: 2 additions & 0 deletions app/svelte/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module '@storybook/core/*';
declare module 'global';
14 changes: 14 additions & 0 deletions app/svelte/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"types": ["webpack-env"],
"resolveJsonModule": true
},
"include": [
"src/**/*"
],
"exclude": [
"src/**/*.test.*"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,4 @@
]
]
}
}
}

1 comment on commit 4f59937

@vercel
Copy link

@vercel vercel bot commented on 4f59937 Nov 12, 2019

Choose a reason for hiding this comment

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

Please sign in to comment.