Skip to content

Commit

Permalink
Fix code style of TS files
Browse files Browse the repository at this point in the history
* not fully waiting for PR merge to master: palantir/tslint#725
  • Loading branch information
misak113 committed Oct 21, 2015
1 parent 6a4d62c commit 48fa02f
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 54 deletions.
4 changes: 3 additions & 1 deletion src/Client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import ClientStateActionCreator, {ClientStateActionName} from './Router/ClientSt
import {Injector} from 'di';
import {Map, fromJS} from 'immutable';
import routes from './config/routes';
/* tslint:disable */
var Router = require('react-router').Router;
var history = require('history');
var patch = require('immutablepatch');
/* tslint:enable */

export interface IClientProps {
injector: Injector;
Expand Down Expand Up @@ -55,7 +57,7 @@ export default class Client extends Component<IClientProps, IClientState, {}> {
this.setState({ clientState: nextClientState });
});
}

render() {
return (
<Router
Expand Down
2 changes: 1 addition & 1 deletion src/DateTime/DateFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

export default class DateFactory {

now() {
return new Date();
}
Expand Down
6 changes: 0 additions & 6 deletions src/Demo/Status.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@

import * as React from 'react';
import {Inject} from 'di-ts';
import Component from '../React/Component';
import DefaultContext from '../React/DefaultContext';
import Dispatcher from '../Flux/Dispatcher';
import ActionBinding from '../Flux/ActionBinding';
import StatusStore from './StatusStore';
import StatusActionCreator, {StatusActionName} from './StatusActionCreator';

export default class Status extends Component<{ status: boolean }, {}, {}> {

Expand Down
2 changes: 1 addition & 1 deletion src/Demo/StatusActionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class StatusActionCreator extends ActionCreator<StatusActionName>
return 'Demo.Status';
}

changeStatus() {
changeStatus(): Action {
return this.createAction(StatusActionName.CHANGE_STATUS);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Demo/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {Inject} from 'di-ts';
import Component from '../React/Component';
import DefaultContext from '../React/DefaultContext';
import Dispatcher from '../Flux/Dispatcher';
import Action from '../Flux/Action';
import StatusActionCreator from './StatusActionCreator';

@Inject
Expand Down
2 changes: 1 addition & 1 deletion src/Flux/ActionBinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class ActionBinding {

get ActionNames() { return this.actionNames; }
get ActionCallback() { return this.actionCallback; }

constructor(
private actionNames: string[],
private actionCallback: (action: Action) => void
Expand Down
2 changes: 1 addition & 1 deletion src/Flux/ActionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ abstract class ActionCreator<ActionName extends ActionNameStatic<any>> {

protected abstract getActionName(): ActionNameStatic<ActionName>;
protected abstract getName(): string;

protected createAction(actionName: ActionName, payload?: any) {
return new Action(this.createActionName(actionName), payload);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Flux/Dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class Dispatcher {
constructor() {
this.eventEmitter = new EventEmitter();
}

dispatch(action: Action) {
this.eventEmitter.emit(action.Name, action);
this.eventEmitter.emit('*', action);
Expand Down
8 changes: 4 additions & 4 deletions src/Layout/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export default class Main extends Component<{ children: any[] }, {}, {}> {
return (
<html>
<head>
<meta charSet="utf-8"/>
<meta charSet='utf-8'/>
<title>App sandbox</title>
<link rel="stylesheet" media="all" href="/css/index.css"></link>
<link rel='stylesheet' media='all' href='/css/index.css'></link>
</head>
<body>
{this.props.children}
<script src="/front-bundle.js"></script>
<script src='/front-bundle.js'></script>
</body>
</html>
);
}
}
}
25 changes: 14 additions & 11 deletions src/React/DefaultContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import ReactComponent from './Component';
import {Injector} from 'di';
import {InjectorMissingException} from './exceptions';

export default function DefaultContext(Context: any): ClassDecorator {
return (Component: ComponentClass<any>) => {
/* tslint:disable:variable-name */
export default function DefaultContext(contextStatic: any): ClassDecorator {
'use strict';
return (ComponentStatic: ComponentClass<any>) => {
/* tslint:enable */
class ComponentWithContext extends ReactComponent<any, any, { injector: Injector }> {

static contextTypes: ValidationMap<any> = {
Expand All @@ -24,31 +27,31 @@ export default function DefaultContext(Context: any): ClassDecorator {
if (!this.context.injector) {
throw new InjectorMissingException('You must pass injector to context of any parent component');
}
Component.contextTypes = Component.contextTypes || {};
var context = this.context.injector.get(Context);
ComponentStatic.contextTypes = ComponentStatic.contextTypes || {};
var context = this.context.injector.get(contextStatic);
Object.keys(context).forEach((key: string) => {
if (!Component.contextTypes[key]) {
Component.contextTypes[key] = PropTypes.any.isRequired;
if (!ComponentStatic.contextTypes[key]) {
ComponentStatic.contextTypes[key] = PropTypes.any.isRequired;
}
ComponentWithContext.childContextTypes[key] = PropTypes.any.isRequired;
});
Object.keys(this.context).forEach((key: string) => {
if (!Component.contextTypes[key]) {
Component.contextTypes[key] = PropTypes.any.isRequired;
if (!ComponentStatic.contextTypes[key]) {
ComponentStatic.contextTypes[key] = PropTypes.any.isRequired;
}
context[key] = this.context[key];
});
return context;
}

render() {
return <Component {...this.props}/>;
return <ComponentStatic {...this.props}/>;
}
}
var contextTypes = Component.contextTypes || {};
var contextTypes = ComponentStatic.contextTypes || {};
Object.keys(contextTypes).forEach((key: string) => {
ComponentWithContext.contextTypes[key] = contextTypes[key];
});
return ComponentWithContext as any as ComponentClass<any>;
}
};
}
6 changes: 4 additions & 2 deletions src/Router/ClientStateActionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import Action from '../Flux/Action';
import ActionCreator from '../Flux/ActionCreator';
import IClientState from './IClientState';
/* tslint:disable */
var diff = require('immutablediff');
/* tslint:enable */

export default class ClientStateActionCreator extends ActionCreator<ClientStateActionName> {

Expand All @@ -14,11 +16,11 @@ export default class ClientStateActionCreator extends ActionCreator<ClientStateA
return 'Router.ClientState';
}

update(updateCallback: (clientState: IClientState) => IClientState) {
update(updateCallback: (clientState: IClientState) => IClientState): Action {
return this.createAction(ClientStateActionName.UPDATE, updateCallback);
}

sendDiff(originalState: IClientState, nextState: IClientState) {
sendDiff(originalState: IClientState, nextState: IClientState): Action {
var ops = diff(originalState, nextState);
return this.createAction(ClientStateActionName.SEND_DIFF, ops.toJS());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Router/ClientStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Map} from 'immutable';

@Inject
export default class ClientStateStore {

private clientState: IClientState;

get ClientState() { return this.clientState; }
Expand Down
23 changes: 12 additions & 11 deletions src/Router/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import ExpressServer from '../Http/ExpressServer';
import ClientStateStore from './ClientStateStore';
import routes from '../config/routes';
import services from '../config/services';
/* tslint:disable */
var match = require('react-router').match;
var renderToString = require('react-dom/server').renderToString;
/* tslint:enable */

@Inject
export class RouterContext {
Expand All @@ -24,7 +26,7 @@ export class RouterContext {
@DefaultContext(RouterContext)
export default class Router extends Component<{ doctype?: string }, { doctype?: string }, RouterContext> {

constructor(props, context) {
constructor(props: { doctype?: string }, context: RouterContext) {
super(props, context);
this.state = {
doctype: props.doctype || '<!doctype html>'
Expand All @@ -37,14 +39,13 @@ export default class Router extends Component<{ doctype?: string }, { doctype?:

private handle(request: Request, response: Response, next: () => void) {
var startTime = process.hrtime();
match({
routes,
var options = {
routes: routes,
location: request.url
}, (
error: Error,
redirectLocation: IRedirectLocation,
renderProps: IRenderProps
) => this.match(error, redirectLocation, renderProps, response, startTime, next));
};
match(options, (error: Error, redirectLocation: IRedirectLocation, renderProps: IRenderProps) => this.match(
error, redirectLocation, renderProps, response, startTime, next
));
}

private match(
Expand Down Expand Up @@ -79,9 +80,9 @@ export default class Router extends Component<{ doctype?: string }, { doctype?:

private getHeader(body: string, totalTime: number[]) {
return {
"Content-Length": body.length,
"Content-Type": "text/html",
"X-Render-Time": this.getMiliseconds(totalTime) + " ms"
'Content-Length': body.length,
'Content-Type': 'text/html',
'X-Render-Time': this.getMiliseconds(totalTime) + ' ms'
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/Router/RoutingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import * as React from 'react';
import {PropTypes, ValidationMap} from 'react';
import Component from '../React/Component';
import {Injector} from 'di';
/* tslint:disable */
var ReactRouterRoutingContext = require('react-router').RoutingContext;
/* tslint:enable */

export interface IRoutingContextProps {
injector: Injector;
Expand Down
6 changes: 1 addition & 5 deletions src/Socket/ClientSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ import HostOptions from '../Http/HostOptions';
export default class ClientSocket {

private sockets: { [namespace: string]: SocketIOClient.Socket } = {};

constructor(
private hostOptions: HostOptions
) {}

getSocketOf(namespace: string) {
var options = {
host: this.hostOptions.host,
port: this.hostOptions.port
};
var uri = this.buildUri(namespace);
return this.sockets[namespace] = this.sockets[namespace] || io(uri);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Socket/ServerSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class ServerSocket {
private socket: SocketIO.Server;

get Socket() { return this.socket; }

constructor(
httpServer: HttpServer
) {
Expand Down
9 changes: 4 additions & 5 deletions src/config/parameters.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

import {Provide} from 'di-ts';
import DispatcherNamespace from '../Socket/DispatcherNamespace'
import ServerOptions from '../Http/ServerOptions'
import HostOptions from '../Http/HostOptions'
import DispatcherNamespace from '../Socket/DispatcherNamespace';
import ServerOptions from '../Http/ServerOptions';
import HostOptions from '../Http/HostOptions';

@Provide(DispatcherNamespace)
export class SocketDispatcherNamespace extends DispatcherNamespace {
constructor() {
super();
this.value = '/dispatcher'
this.value = '/dispatcher';
}
}

Expand All @@ -21,7 +21,6 @@ export class HttpServerOptions extends ServerOptions {
}
}


@Provide(HostOptions)
export class HttpHostOptions extends HostOptions {
constructor() {
Expand Down
4 changes: 3 additions & 1 deletion src/config/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import * as React from 'react';
import Main from '../Layout/Main';
import Homepage from '../Demo/Homepage';
/* tslint:disable */
var Route = require('react-router').Route;
var IndexRoute = require('react-router').IndexRoute;
/* tslint:enable */

var routes = (
<Route path="/" component={Main}>
<Route path='/' component={Main}>
<IndexRoute component={Homepage}/>
</Route>
);
Expand Down

0 comments on commit 48fa02f

Please sign in to comment.