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 typescript #9018

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions app/ember/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"dependencies": {
"@ember/test-helpers": "^1.5.0",
"@storybook/addons": "5.3.0-beta.13",
"@storybook/core": "5.3.0-beta.13",
"core-js": "^3.0.1",
"global": "^4.3.2",
Expand Down
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 = '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 };
Original file line number Diff line number Diff line change
@@ -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 @@ -13,20 +15,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,10 +57,8 @@ export default function renderMain({
selectedStory,
showMain,
showError,
// forceRender,
}) {
}: RenderMainArgs) {
const element = storyFn();

if (!element) {
showError({
title: `Expecting a Ember element from the story: "${selectedStory}" of "${selectedKind}".`,
Expand Down
24 changes: 24 additions & 0 deletions app/ember/src/client/preview/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { StoryFn } from '@storybook/addons';

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.
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
3 changes: 3 additions & 0 deletions app/ember/src/typings.d.ts
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"types": ["webpack-env"],
"resolveJsonModule": true
},
"include": ["src/**/*", "package.json"],
"exclude": ["src/**/*.test.*"]
}