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 ember to TS #9020

Merged
merged 2 commits into from
Dec 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
File renamed without changes.
Expand Up @@ -15,7 +15,8 @@ export const {
} = clientApi;

const framework = 'ember';
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 };
@@ -1,6 +1,8 @@
/* eslint-disable no-undef */
import { window, document } from 'global';
import dedent from 'ts-dedent';
import { RenderMainArgs, ElementArgs, OptionsArgs } from './types';

declare let Ember: any;

const rootEl = document.getElementById('root');

Expand All @@ -14,19 +16,19 @@ const app = window.require(`${window.STORYBOOK_NAME}/app`).default.create({
let lastPromise = app.boot();
let hasRendered = false;

function render(options, el) {
function render(options: OptionsArgs, el: ElementArgs) {
const { template, context = {}, element } = options;

if (hasRendered) {
lastPromise = lastPromise.then(instance => instance.destroy());
lastPromise = lastPromise.then((instance: any) => instance.destroy());
}

lastPromise = lastPromise
.then(() => {
const appInstancePrivate = app.buildInstance();
return appInstancePrivate.boot().then(() => appInstancePrivate);
})
.then(instance => {
.then((instance: any) => {
instance.register(
'component:story-mode',
Ember.Component.extend({
Expand Down Expand Up @@ -56,8 +58,7 @@ export default function renderMain({
selectedStory,
showMain,
showError,
// forceRender,
}) {
}: RenderMainArgs) {
const element = storyFn();

if (!element) {
Expand Down
24 changes: 24 additions & 0 deletions app/ember/src/client/preview/types.ts
@@ -0,0 +1,24 @@
import { StoryFn } from '@storybook/addons'; // eslint-disable-line

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

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

export interface ElementArgs {
el: HTMLElement;
}

export interface OptionsArgs {
template: any;
context: any;
element: any;
}
File renamed without changes.
@@ -1,6 +1,7 @@
import { precompile } from 'ember-source/dist/ember-template-compiler';
import { Configuration } from 'webpack'; // eslint-disable-line

export function babel(config) {
export function babel(config: Configuration) {
const babelConfigPlugins = config.plugins || [];

const extraPlugins = [
Expand Down
File renamed without changes.
@@ -1,4 +1,4 @@
import packageJson from '../../package.json';
const packageJson = require('../../package.json');

export default {
packageJson,
Expand Down
3 changes: 3 additions & 0 deletions app/ember/src/typings.d.ts
@@ -0,0 +1,3 @@
declare module '@storybook/core/*';
declare module 'ember-source/dist/ember-template-compiler';
declare module 'global';
10 changes: 10 additions & 0 deletions app/ember/tsconfig.json
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"types": ["webpack-env"],
"resolveJsonModule": true
},
"include": ["src/**/*", "package.json"],
"exclude": ["src/**/*.test.*"]
}