mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-19 05:02:40 +08:00
CHANGE tslint config to no longer conflict with prettier && FIX a ton of linting issues on .ts
This commit is contained in:
parent
9017034341
commit
65583e5671
@ -81,7 +81,7 @@ export default class NotesPanel extends React.Component<Props, NotesPanelState>
|
||||
} else {
|
||||
this.setState({ value: undefined });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { active } = this.props;
|
||||
|
@ -2,6 +2,7 @@
|
||||
// to provide @Inputs and subscribe to @Outputs, see
|
||||
// https://github.com/angular/angular/issues/15360
|
||||
// For the time being, the ViewContainerRef approach works pretty well.
|
||||
|
||||
import {
|
||||
Component,
|
||||
Inject,
|
||||
@ -13,6 +14,7 @@ import {
|
||||
EventEmitter,
|
||||
SimpleChanges,
|
||||
SimpleChange,
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
} from '@angular/core';
|
||||
import { STORY } from './app.token';
|
||||
import { NgStory, ICollection } from './types';
|
||||
|
@ -1,3 +1,4 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { InjectionToken } from '@angular/core';
|
||||
import { NgStory } from './types';
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { Component, Type } from '@angular/core';
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { FormsModule } from '@angular/forms';
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app.component';
|
||||
import { STORY } from './app.token';
|
||||
@ -15,47 +18,32 @@ const getModuleMeta = (
|
||||
return {
|
||||
declarations: [...declarations, ...(moduleMetadata.declarations || [])],
|
||||
imports: [BrowserModule, FormsModule, ...(moduleMetadata.imports || [])],
|
||||
providers: [
|
||||
{ provide: STORY, useValue: Object.assign({}, data) },
|
||||
...(moduleMetadata.providers || []),
|
||||
],
|
||||
providers: [{ provide: STORY, useValue: { ...data } }, ...(moduleMetadata.providers || [])],
|
||||
entryComponents: [...entryComponents, ...(moduleMetadata.entryComponents || [])],
|
||||
schemas: [...(moduleMetadata.schemas || [])],
|
||||
bootstrap: [...bootstrap],
|
||||
};
|
||||
};
|
||||
|
||||
const createComponentFromTemplate = (template: string): Function => {
|
||||
const createComponentFromTemplate = (template: string) => {
|
||||
const componentClass = class DynamicComponent {};
|
||||
|
||||
return Component({
|
||||
template: template,
|
||||
template,
|
||||
})(componentClass);
|
||||
};
|
||||
|
||||
export const initModuleData = (storyObj: NgStory): any => {
|
||||
const { component, template, props, moduleMetadata = {} } = storyObj;
|
||||
|
||||
let AnnotatedComponent;
|
||||
|
||||
if (template) {
|
||||
AnnotatedComponent = createComponentFromTemplate(template);
|
||||
} else {
|
||||
AnnotatedComponent = component;
|
||||
}
|
||||
const AnnotatedComponent = template ? createComponentFromTemplate(template) : component;
|
||||
|
||||
const story = {
|
||||
component: AnnotatedComponent,
|
||||
props,
|
||||
};
|
||||
|
||||
const moduleMeta = getModuleMeta(
|
||||
[AppComponent, AnnotatedComponent],
|
||||
[AnnotatedComponent],
|
||||
[AppComponent],
|
||||
story,
|
||||
moduleMetadata
|
||||
);
|
||||
const moduleMeta = getModuleMeta([AppComponent, AnnotatedComponent], [AnnotatedComponent], [AppComponent], story, moduleMetadata);
|
||||
|
||||
return {
|
||||
AppComponent,
|
||||
|
@ -1,9 +1,9 @@
|
||||
export interface NgModuleMetadata {
|
||||
declarations?: Array<any>;
|
||||
entryComponents?: Array<any>;
|
||||
imports?: Array<any>;
|
||||
schemas?: Array<any>;
|
||||
providers?: Array<any>;
|
||||
declarations?: any[];
|
||||
entryComponents?: any[];
|
||||
imports?: any[];
|
||||
schemas?: any[];
|
||||
providers?: any[];
|
||||
}
|
||||
|
||||
export interface ICollection {
|
||||
|
@ -9,10 +9,7 @@ export const moduleMetadata = (metadata: Partial<NgModuleMetadata>) => (storyFn:
|
||||
...story,
|
||||
moduleMetadata: {
|
||||
declarations: [...(metadata.declarations || []), ...(storyMetadata.declarations || [])],
|
||||
entryComponents: [
|
||||
...(metadata.entryComponents || []),
|
||||
...(storyMetadata.entryComponents || []),
|
||||
],
|
||||
entryComponents: [...(metadata.entryComponents || []), ...(storyMetadata.entryComponents || [])],
|
||||
imports: [...(metadata.imports || []), ...(storyMetadata.imports || [])],
|
||||
schemas: [...(metadata.schemas || []), ...(storyMetadata.schemas || [])],
|
||||
providers: [...(metadata.providers || []), ...(storyMetadata.providers || [])],
|
||||
|
@ -7,7 +7,12 @@ import { STORY } from './app.token';
|
||||
import { NgModuleMetadata, IGetStory, NgStory } from './types';
|
||||
|
||||
let platform: any = null;
|
||||
let promises: Promise<NgModuleRef<any>>[] = [];
|
||||
let promises: Array<Promise<NgModuleRef<any>>> = [];
|
||||
|
||||
const moduleClass = class DynamicModule {};
|
||||
const componentClass = class DynamicComponent {};
|
||||
|
||||
type DynamicComponentType = typeof componentClass;
|
||||
|
||||
const getModule = (
|
||||
declarations: Array<Type<any> | any[]>,
|
||||
@ -19,53 +24,34 @@ const getModule = (
|
||||
const moduleMeta = {
|
||||
declarations: [...declarations, ...(moduleMetadata.declarations || [])],
|
||||
imports: [BrowserModule, FormsModule, ...(moduleMetadata.imports || [])],
|
||||
providers: [
|
||||
{ provide: STORY, useValue: Object.assign({}, data) },
|
||||
...(moduleMetadata.providers || []),
|
||||
],
|
||||
providers: [{ provide: STORY, useValue: { ...data } }, ...(moduleMetadata.providers || [])],
|
||||
entryComponents: [...entryComponents, ...(moduleMetadata.entryComponents || [])],
|
||||
schemas: [...(moduleMetadata.schemas || [])],
|
||||
bootstrap: [...bootstrap],
|
||||
};
|
||||
|
||||
const moduleClass = class DynamicModule {};
|
||||
|
||||
return NgModule(moduleMeta)(moduleClass);
|
||||
};
|
||||
|
||||
const createComponentFromTemplate = (template: string, styles: string[]): Function => {
|
||||
const componentClass = class DynamicComponent {};
|
||||
|
||||
const createComponentFromTemplate = (template: string, styles: string[]) => {
|
||||
return Component({
|
||||
template,
|
||||
styles,
|
||||
})(componentClass);
|
||||
};
|
||||
|
||||
const initModule = (currentStory: IGetStory): Function => {
|
||||
const initModule = (currentStory: IGetStory) => {
|
||||
const storyObj = currentStory();
|
||||
const { component, template, props, styles, moduleMetadata = {} } = storyObj;
|
||||
|
||||
let AnnotatedComponent;
|
||||
|
||||
if (template) {
|
||||
AnnotatedComponent = createComponentFromTemplate(template, styles);
|
||||
} else {
|
||||
AnnotatedComponent = component;
|
||||
}
|
||||
let AnnotatedComponent = template ? createComponentFromTemplate(template, styles) : component;
|
||||
|
||||
const story = {
|
||||
component: AnnotatedComponent,
|
||||
props,
|
||||
};
|
||||
|
||||
return getModule(
|
||||
[AppComponent, AnnotatedComponent],
|
||||
[AnnotatedComponent],
|
||||
[AppComponent],
|
||||
story,
|
||||
moduleMetadata
|
||||
);
|
||||
return getModule([AppComponent, AnnotatedComponent], [AnnotatedComponent], [AppComponent], story, moduleMetadata);
|
||||
};
|
||||
|
||||
const staticRoot = document.getElementById('root');
|
||||
@ -74,7 +60,7 @@ const insertDynamicRoot = () => {
|
||||
staticRoot.appendChild(app);
|
||||
};
|
||||
|
||||
const draw = (newModule: Function): void => {
|
||||
const draw = (newModule: DynamicComponentType): void => {
|
||||
if (!platform) {
|
||||
insertDynamicRoot();
|
||||
try {
|
||||
|
@ -1,9 +1,9 @@
|
||||
export interface NgModuleMetadata {
|
||||
declarations?: Array<any>;
|
||||
entryComponents?: Array<any>;
|
||||
imports?: Array<any>;
|
||||
schemas?: Array<any>;
|
||||
providers?: Array<any>;
|
||||
declarations?: any[];
|
||||
entryComponents?: any[];
|
||||
imports?: any[];
|
||||
schemas?: any[];
|
||||
providers?: any[];
|
||||
}
|
||||
|
||||
export interface ICollection {
|
||||
|
@ -7,39 +7,29 @@ import { Component, Output, EventEmitter } from '@angular/core';
|
||||
<h1>Welcome to storybook</h1>
|
||||
<p>This is a UI component dev environment for your app.</p>
|
||||
<p>
|
||||
We've added some basic stories inside the
|
||||
<span class="inline-code">src/stories</span> directory. <br />
|
||||
A story is a single state of one or more UI components. You can have as many stories as you
|
||||
want. <br />
|
||||
We've added some basic stories inside the <span class="inline-code">src/stories</span> directory. <br />
|
||||
A story is a single state of one or more UI components. You can have as many stories as you want. <br />
|
||||
(Basically a story is like a visual test case.)
|
||||
</p>
|
||||
<p>
|
||||
See these sample
|
||||
<a (click)="showApp.emit($event)" role="button" tabIndex="0">stories</a> for a component
|
||||
called <span class="inline-code">Button</span> .
|
||||
See these sample <a (click)="showApp.emit($event)" role="button" tabIndex="0">stories</a> for a component called
|
||||
<span class="inline-code">Button</span> .
|
||||
</p>
|
||||
<p>
|
||||
Just like that, you can add your own components as stories. <br />
|
||||
You can also edit those components and see changes right away. <br />
|
||||
(Try editing the <span class="inline-code">Button</span> stories located at
|
||||
<span class="inline-code">src/stories/index.js</span>.)
|
||||
(Try editing the <span class="inline-code">Button</span> stories located at <span class="inline-code">src/stories/index.js</span>.)
|
||||
</p>
|
||||
<p>
|
||||
Usually we create stories with smaller UI components in the app.<br />
|
||||
Have a look at the
|
||||
<a
|
||||
href="https://storybook.js.org/basics/writing-stories"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Writing Stories
|
||||
</a>
|
||||
section in our documentation.
|
||||
<a href="https://storybook.js.org/basics/writing-stories" target="_blank" rel="noopener noreferrer"> Writing Stories </a> section in
|
||||
our documentation.
|
||||
</p>
|
||||
<p class="note">
|
||||
<b>NOTE:</b> <br />
|
||||
Have a look at the <span class="inline-code">.storybook/webpack.config.js</span> to add
|
||||
webpack loaders and plugins you are using in this project.
|
||||
Have a look at the <span class="inline-code">.storybook/webpack.config.js</span> to add webpack loaders and plugins you are using in
|
||||
this project.
|
||||
</p>
|
||||
</main>
|
||||
`,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { AppPage } from './app.po';
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import 'jasmine';
|
||||
|
||||
describe('ng5test App', () => {
|
||||
@ -10,6 +11,6 @@ describe('ng5test App', () => {
|
||||
|
||||
it('should display welcome message', () => {
|
||||
page.navigateTo();
|
||||
expect(<any>page.getParagraphText()).toEqual('Welcome to app!');
|
||||
expect(page.getParagraphText() as any).toEqual('Welcome to app!');
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'jest-preset-angular';
|
||||
import './globalMocks';
|
||||
|
||||
// tslint:disable-next-line:no-var-requires no-implicit-dependencies
|
||||
require('babel-plugin-require-context-hook/register')();
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { TestBed, async } from '@angular/core/testing';
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import 'jasmine';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
|
@ -7,17 +7,14 @@ import 'zone.js/dist/jasmine-patch';
|
||||
import 'zone.js/dist/async-test';
|
||||
import 'zone.js/dist/fake-async-test';
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting,
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
|
||||
declare const __karma__: any;
|
||||
declare const require: any;
|
||||
|
||||
// Prevent Karma from running prematurely.
|
||||
__karma__.loaded = function() {};
|
||||
__karma__.loaded = () => {};
|
||||
|
||||
// First, initialize the Angular testing environment.
|
||||
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
||||
|
@ -18,7 +18,7 @@
|
||||
* BROWSER POLYFILLS
|
||||
*/
|
||||
|
||||
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
|
||||
/* IE9, IE10 and IE11 requires all of the following polyfills. */
|
||||
// import 'core-js/es6/symbol';
|
||||
// import 'core-js/es6/object';
|
||||
// import 'core-js/es6/function';
|
||||
@ -37,14 +37,14 @@
|
||||
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
||||
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
||||
|
||||
/** Evergreen browsers require these. **/
|
||||
/* Evergreen browsers require these. */
|
||||
import 'core-js/es6/reflect';
|
||||
import 'core-js/es7/reflect';
|
||||
|
||||
/**
|
||||
* Required to support Web Animations `@angular/animation`.
|
||||
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
|
||||
**/
|
||||
*/
|
||||
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
||||
|
||||
/***************************************************************************************************
|
||||
|
@ -4,10 +4,7 @@ import { AppComponent } from '../app/app.component';
|
||||
|
||||
storiesOf('Addon|Background', module)
|
||||
.addParameters({
|
||||
backgrounds: [
|
||||
{ name: 'twitter', value: '#00aced', default: true },
|
||||
{ name: 'facebook', value: '#3b5998' },
|
||||
],
|
||||
backgrounds: [{ name: 'twitter', value: '#00aced', default: true }, { name: 'facebook', value: '#3b5998' }],
|
||||
})
|
||||
.add('background component', () => ({
|
||||
component: AppComponent,
|
||||
@ -21,10 +18,7 @@ storiesOf('Addon|Background', module)
|
||||
})
|
||||
)
|
||||
.addParameters({
|
||||
backgrounds: [
|
||||
{ name: 'twitter', value: '#00aced', default: true },
|
||||
{ name: 'facebook', value: '#3b5998' },
|
||||
],
|
||||
backgrounds: [{ name: 'twitter', value: '#00aced', default: true }, { name: 'facebook', value: '#3b5998' }],
|
||||
})
|
||||
.add('background template', () => ({
|
||||
template: `<storybook-button-component [text]="text" (onClick)="onClick($event)"></storybook-button-component>`,
|
||||
|
@ -1,18 +1,7 @@
|
||||
import { storiesOf } from '@storybook/angular';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
|
||||
import {
|
||||
withKnobs,
|
||||
text,
|
||||
number,
|
||||
boolean,
|
||||
array,
|
||||
select,
|
||||
radios,
|
||||
color,
|
||||
date,
|
||||
button,
|
||||
} from '@storybook/addon-knobs';
|
||||
import { withKnobs, text, number, boolean, array, select, radios, color, date, button } from '@storybook/addon-knobs';
|
||||
|
||||
import { SimpleKnobsComponent } from './knobs.component';
|
||||
import { AllKnobsComponent } from './all-knobs.component';
|
||||
|
@ -3,9 +3,7 @@ import { Component, Input, OnInit, OnChanges, SimpleChanges } from '@angular/cor
|
||||
@Component({
|
||||
selector: 'storybook-simple-knobs-component',
|
||||
template: `
|
||||
<div
|
||||
[ngStyle]="{ border: '2px dotted ' + border, 'padding.px': '8 22', 'border-radius.px': '8' }"
|
||||
>
|
||||
<div [ngStyle]="{ border: '2px dotted ' + border, 'padding.px': '8 22', 'border-radius.px': '8' }">
|
||||
<h1>My name is {{ name }},</h1>
|
||||
<h3>today is {{ today | date }}</h3>
|
||||
<p *ngIf="stock">I have a stock of {{ stock }} {{ fruit }}, costing $ {{ price }} each.</p>
|
||||
|
@ -11,11 +11,7 @@ export class DiComponent {
|
||||
@Input()
|
||||
title: string;
|
||||
|
||||
constructor(
|
||||
protected injector: Injector,
|
||||
protected elRef: ElementRef,
|
||||
@Inject(TEST_TOKEN) protected testToken: number
|
||||
) {}
|
||||
constructor(protected injector: Injector, protected elRef: ElementRef, @Inject(TEST_TOKEN) protected testToken: number) {}
|
||||
|
||||
isAllDeps(): boolean {
|
||||
return Boolean(this.testToken && this.elRef && this.injector && this.title);
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { storiesOf } from '@storybook/angular';
|
||||
import { storiesOf, moduleMetadata } from '@storybook/angular';
|
||||
import { withKnobs, text } from '@storybook/addon-knobs';
|
||||
|
||||
import { NameComponent } from './moduleMetadata/name.component';
|
||||
import { CustomPipePipe } from './moduleMetadata/custom.pipe';
|
||||
import { moduleMetadata } from '@storybook/angular';
|
||||
|
||||
storiesOf('Custom|Pipes', module)
|
||||
.addDecorator(
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { storiesOf } from '@storybook/angular';
|
||||
import { storiesOf, moduleMetadata } from '@storybook/angular';
|
||||
import { withKnobs, text } from '@storybook/addon-knobs';
|
||||
|
||||
import { DummyService } from './moduleMetadata/dummy.service';
|
||||
import { ServiceComponent } from './moduleMetadata/service.component';
|
||||
import { moduleMetadata } from '@storybook/angular';
|
||||
|
||||
storiesOf('Custom|Providers', module)
|
||||
.addDecorator(
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { storiesOf } from '@storybook/angular';
|
||||
import { storiesOf, moduleMetadata } from '@storybook/angular';
|
||||
import { Welcome, Button } from '@storybook/angular/demo';
|
||||
import { moduleMetadata } from '@storybook/angular';
|
||||
import { linkTo } from '@storybook/addon-links';
|
||||
import { environment } from 'environments/environment';
|
||||
import { environment } from '../environments/environment';
|
||||
|
||||
if (environment) {
|
||||
// This ensures that the basePath typeScript feature works with storybook
|
||||
|
@ -3,10 +3,6 @@ import { storiesOf } from '@storybook/react';
|
||||
import { action } from '@storybook/addon-actions';
|
||||
import Button from './Button';
|
||||
|
||||
storiesOf('Button', module).add(
|
||||
'simple button',
|
||||
() => <Button onClick={action('button clicked')}>OK</Button>,
|
||||
{
|
||||
info: { inline: true },
|
||||
},
|
||||
);
|
||||
storiesOf('Button', module).add('simple button', () => <Button onClick={action('button clicked')}>OK</Button>, {
|
||||
info: { inline: true },
|
||||
});
|
||||
|
@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@storybook/channels": "5.0.0-alpha.9",
|
||||
"@storybook/client-logger": "5.0.0-alpha.9",
|
||||
"global": "^4.3.2",
|
||||
"util-deprecate": "^1.0.2"
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
import global from 'global';
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { ReactElement } from 'react';
|
||||
import { Channel } from '@storybook/channels';
|
||||
import logger from '@storybook/client-logger';
|
||||
@ -50,40 +51,40 @@ export class AddonStore {
|
||||
}
|
||||
|
||||
return this.channel;
|
||||
}
|
||||
};
|
||||
hasChannel = (): boolean => !!this.channel;
|
||||
setChannel = (channel: Channel): void => {
|
||||
this.channel = channel;
|
||||
}
|
||||
};
|
||||
|
||||
getElements = (type: Types): Collection => {
|
||||
if (!this.elements[type]) {
|
||||
this.elements[type] = {};
|
||||
}
|
||||
return this.elements[type];
|
||||
}
|
||||
};
|
||||
addPanel = (name: string, options: Addon): void => {
|
||||
this.add(name, {
|
||||
type: types.PANEL,
|
||||
...options,
|
||||
});
|
||||
}
|
||||
};
|
||||
add = (name: string, addon: Addon) => {
|
||||
const { type } = addon;
|
||||
const collection = this.getElements(type);
|
||||
collection[name] = { id: name, ...addon };
|
||||
}
|
||||
};
|
||||
|
||||
register = (name: string, registerCallback: (api: any) => void): void => {
|
||||
if (this.loaders[name]) {
|
||||
logger.warn(`${name} was loaded twice, this could have bad side-effects`);
|
||||
}
|
||||
this.loaders[name] = registerCallback;
|
||||
}
|
||||
};
|
||||
|
||||
loadAddons = (api: any) => {
|
||||
Object.values(this.loaders).forEach(value => value(api));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Enforce addons store to be a singleton
|
||||
|
@ -1,13 +1,9 @@
|
||||
import deprecate from 'util-deprecate';
|
||||
import { makeDecorator, StoryContext } from './make-decorator';
|
||||
import { makeDecorator, StoryContext, StoryGetter } from './make-decorator';
|
||||
|
||||
// Copy & paste from internal api: core/client/preview/client_api
|
||||
export const defaultDecorateStory = (getStory: Function, decorators: Function[]) =>
|
||||
decorators.reduce(
|
||||
(decorated, decorator) => (context: StoryContext) =>
|
||||
decorator(() => decorated(context), context),
|
||||
getStory
|
||||
);
|
||||
export const defaultDecorateStory = (getStory: StoryGetter, decorators: DecoratorFn[]): StoryGetter =>
|
||||
decorators.reduce((decorated, decorator) => (context: StoryContext) => decorator(() => decorated(context), context), getStory);
|
||||
|
||||
jest.mock('util-deprecate');
|
||||
let deprecatedFns: any[] = [];
|
||||
@ -20,6 +16,12 @@ let deprecatedFns: any[] = [];
|
||||
return deprecatedFn;
|
||||
});
|
||||
|
||||
const baseContext = {
|
||||
name: '',
|
||||
kind: '',
|
||||
parameters: {},
|
||||
};
|
||||
|
||||
describe('makeDecorator', () => {
|
||||
it('returns a decorator that passes parameters on the parameters argument', () => {
|
||||
const wrapper = jest.fn();
|
||||
@ -27,7 +29,7 @@ describe('makeDecorator', () => {
|
||||
const story = jest.fn();
|
||||
const decoratedStory = defaultDecorateStory(story, [decorator]);
|
||||
|
||||
const context = { parameters: { test: 'test-val' } };
|
||||
const context = { kind: '', name: '', parameters: { test: 'test-val' } };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).toHaveBeenCalledWith(expect.any(Function), context, { parameters: 'test-val' });
|
||||
@ -40,7 +42,7 @@ describe('makeDecorator', () => {
|
||||
const options = 'test-val';
|
||||
const decoratedStory = defaultDecorateStory(story, [decorator(options)]);
|
||||
|
||||
const context = {};
|
||||
const context = { ...baseContext };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).toHaveBeenCalledWith(expect.any(Function), context, { options: 'test-val' });
|
||||
@ -53,7 +55,7 @@ describe('makeDecorator', () => {
|
||||
const options = 'test-val';
|
||||
const decoratedStory = defaultDecorateStory(story, [decorator(options)]);
|
||||
|
||||
const context = { parameters: { test: 'test-val' } };
|
||||
const context = { ...baseContext, parameters: { test: 'test-val' } };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).toHaveBeenCalledWith(expect.any(Function), context, {
|
||||
@ -68,7 +70,7 @@ describe('makeDecorator', () => {
|
||||
const story = jest.fn();
|
||||
const decoratedStory = defaultDecorateStory(story, [decorator]);
|
||||
|
||||
const context = {};
|
||||
const context = { ...baseContext };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).toHaveBeenCalledWith(expect.any(Function), context, {});
|
||||
@ -85,7 +87,7 @@ describe('makeDecorator', () => {
|
||||
const story = jest.fn();
|
||||
const decoratedStory = defaultDecorateStory(story, [decorator]);
|
||||
|
||||
const context = {};
|
||||
const context = { ...baseContext };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).not.toHaveBeenCalled();
|
||||
@ -103,7 +105,7 @@ describe('makeDecorator', () => {
|
||||
const story = jest.fn();
|
||||
const decoratedStory = defaultDecorateStory(story, [decorator]);
|
||||
|
||||
const context = { disable: true };
|
||||
const context = { ...baseContext, parameters: { test: { disable: true } } };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).not.toHaveBeenCalled();
|
||||
@ -125,7 +127,7 @@ describe('makeDecorator', () => {
|
||||
expect(deprecatedFns).toHaveLength(1);
|
||||
expect(deprecatedFns[0].warning).toMatch('addDecorator(test)');
|
||||
|
||||
const context = {};
|
||||
const context = { ...baseContext };
|
||||
decoratedStory(context);
|
||||
|
||||
expect(wrapper).toHaveBeenCalledWith(expect.any(Function), context, {
|
||||
|
@ -1,22 +1,21 @@
|
||||
import deprecate from 'util-deprecate';
|
||||
|
||||
export interface StoryContext {
|
||||
story: string;
|
||||
name: string;
|
||||
kind: string;
|
||||
parameters: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
|
||||
export interface WrapperSettings {
|
||||
options: object;
|
||||
parameters: any;
|
||||
parameters: object;
|
||||
}
|
||||
|
||||
export type StoryGetter = (context: StoryContext) => any;
|
||||
|
||||
export type StoryWrapper = (
|
||||
getStory: StoryGetter,
|
||||
context: StoryContext,
|
||||
settings: WrapperSettings
|
||||
) => any;
|
||||
export type StoryWrapper = (getStory: StoryGetter, context: StoryContext, settings: WrapperSettings) => any;
|
||||
|
||||
type MakeDecoratorResult = (...args: any) => any;
|
||||
|
||||
@ -35,7 +34,7 @@ export const makeDecorator: MakeDecoratorResult = ({
|
||||
skipIfNoParametersOrOptions = false,
|
||||
allowDeprecatedUsage = false,
|
||||
}: MakeDecoratorOptions) => {
|
||||
const decorator: any = (options: object) => (getStory: any, context: any) => {
|
||||
const decorator: any = (options: object) => (getStory: StoryGetter, context: StoryContext) => {
|
||||
const parameters = context.parameters && context.parameters[parameterName];
|
||||
|
||||
if (parameters && parameters.disable) {
|
||||
|
@ -22,10 +22,7 @@ export class WebsocketTransport {
|
||||
private isReady = false;
|
||||
|
||||
constructor({ url, onError }: WebsocketTransportArgs) {
|
||||
this.connect(
|
||||
url,
|
||||
onError
|
||||
);
|
||||
this.connect(url, onError);
|
||||
}
|
||||
|
||||
setHandler(handler: ChannelHandler) {
|
||||
|
@ -189,8 +189,7 @@ describe('Channel', () => {
|
||||
const eventName = 'event1';
|
||||
const listenerToBeRemoved = jest.fn();
|
||||
const listeners = [jest.fn(), jest.fn()];
|
||||
const findListener = (listener: Listener) =>
|
||||
channel.listeners(eventName).find(_listener => _listener === listener);
|
||||
const findListener = (listener: Listener) => channel.listeners(eventName).find(_listener => _listener === listener);
|
||||
|
||||
listeners.forEach(fn => channel.addListener(eventName, fn));
|
||||
channel.addListener(eventName, listenerToBeRemoved);
|
||||
|
@ -1,6 +1,5 @@
|
||||
import * as EventsPackageExport from '.';
|
||||
import EventsDefaultExport from '.';
|
||||
import { CHANNEL_CREATED } from '.';
|
||||
import EventsDefaultExport, { CHANNEL_CREATED } from './index';
|
||||
|
||||
describe('Core Events', () => {
|
||||
it('Should export the module as a namespace', () => {
|
||||
|
@ -1,3 +1,4 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { _STORE_REDUCERS } from '@ngrx/store';
|
||||
import { OperatingSystem } from './platform';
|
||||
|
||||
@ -217,7 +218,7 @@ const uiMap = new KeyCodeStrMap();
|
||||
const userSettingsUSMap = new KeyCodeStrMap();
|
||||
const userSettingsGeneralMap = new KeyCodeStrMap();
|
||||
|
||||
(function() {
|
||||
(() => {
|
||||
function define(
|
||||
keyCode: KeyCode,
|
||||
uiLabel: string,
|
||||
@ -353,6 +354,7 @@ const userSettingsGeneralMap = new KeyCodeStrMap();
|
||||
define(KeyCode.NUMPAD_DIVIDE, 'NumPad_Divide');
|
||||
})();
|
||||
|
||||
// tslint:disable-next-line:no-namespace
|
||||
export namespace KeyCodeUtils {
|
||||
export function toString(keyCode: KeyCode): string {
|
||||
return uiMap.keyCodeToStr(keyCode);
|
||||
@ -534,6 +536,7 @@ export class ResolveKeybindingPart {
|
||||
}
|
||||
}
|
||||
|
||||
// tslint:disable-next-line:max-classes-per-file
|
||||
export abstract class ResolvedKeybinding {
|
||||
/**
|
||||
* This prints the binding in a format suitable for displaying in the UI.
|
||||
|
@ -260,7 +260,7 @@ export class ScanCodeBinding {
|
||||
}
|
||||
}
|
||||
|
||||
(function() {
|
||||
(() => {
|
||||
function d(intScanCode: ScanCode, strScanCode: string): void {
|
||||
scanCodeIntToStr[intScanCode] = strScanCode;
|
||||
scanCodeStrToInt[strScanCode] = intScanCode;
|
||||
@ -461,7 +461,7 @@ export class ScanCodeBinding {
|
||||
d(ScanCode.MailSend, 'MailSend');
|
||||
})();
|
||||
|
||||
(function() {
|
||||
(() => {
|
||||
for (let i = 0; i <= ScanCode.MAX_VALUE; i++) {
|
||||
IMMUTABLE_CODE_TO_KEYCODE[i] = -1;
|
||||
}
|
||||
|
30
tslint.json
30
tslint.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"extends": ["tslint-plugin-prettier", "tslint-config-prettier"],
|
||||
"rulesDirectory": ["node_modules/codelyzer"],
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rulesDirectory": ["node_modules/codelyzer", "tslint-plugin-prettier"],
|
||||
"rules": {
|
||||
"prettier": {
|
||||
"severity": "warning",
|
||||
@ -17,14 +17,10 @@
|
||||
"class-name": true,
|
||||
"comment-format": [true, "check-space"],
|
||||
"curly": true,
|
||||
"eofline": true,
|
||||
"forin": true,
|
||||
"import-blacklist": [true, "rxjs"],
|
||||
"import-spacing": true,
|
||||
"indent": [true, "spaces", 2],
|
||||
"interface-over-type-literal": true,
|
||||
"label-position": true,
|
||||
"max-line-length": [true, 140],
|
||||
"member-access": false,
|
||||
"member-ordering": [
|
||||
true,
|
||||
@ -33,12 +29,15 @@
|
||||
}
|
||||
],
|
||||
"no-arg": true,
|
||||
"interface-name": false,
|
||||
"max-classes-per-file": [true, 4],
|
||||
"no-bitwise": true,
|
||||
"no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
|
||||
"no-construct": true,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-super": true,
|
||||
"no-empty": false,
|
||||
"no-submodule-imports": false,
|
||||
"no-empty-interface": true,
|
||||
"no-eval": true,
|
||||
"no-inferrable-types": [true, "ignore-params"],
|
||||
@ -48,28 +47,17 @@
|
||||
"no-string-literal": false,
|
||||
"no-string-throw": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unnecessary-initializer": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-var-keyword": true,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"one-line": [true, "check-open-brace", "check-catch", "check-else", "check-whitespace"],
|
||||
"prefer-const": true,
|
||||
"quotemark": [true, "single", "jsx-double"],
|
||||
"prefer-const": false,
|
||||
"quotemark": false,
|
||||
"radix": true,
|
||||
"semicolon": [true, "always"],
|
||||
"no-implicit-dependencies": [true, "dev"],
|
||||
"triple-equals": [true, "allow-null-check"],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"unified-signatures": true,
|
||||
"variable-name": false,
|
||||
"directive-selector": [true, "attribute", "app", "camelCase"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user