Skip to content

Commit

Permalink
Merge pull request #9020 from aromanarguello/emberType
Browse files Browse the repository at this point in the history
Migrate ember to TS
  • Loading branch information
aromanarguello committed Dec 22, 2019
2 parents 03efaa6 + 180ae51 commit fc20697
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 10 deletions.
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 = '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 @@ -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
Original file line number Diff line number Diff line change
@@ -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.
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.
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
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.*"]
}

0 comments on commit fc20697

Please sign in to comment.