Skip to content

Commit

Permalink
[_refactored] TypeScript formatting
Browse files Browse the repository at this point in the history
Summary:
- Added whitespace to TypeScript annotations
- Replaced `_` with `kwargs` in type declarations
- Fallback to browser errors for missing kwargs

Closes #84

Reviewers: O2 Material Motion, featherless, shyndman

Reviewed By: O2 Material Motion, featherless, shyndman

Subscribers: markwei, featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D1732
  • Loading branch information
appsforartists committed Oct 21, 2016
1 parent 670123f commit 90b002c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "dist/index.js",
"types": "src/index.ts",
"scripts": {
"build": "$(npm bin)/tsickle",
"test": "$(npm bin)/karma start"
},
"dependencies": {},
Expand Down
18 changes: 14 additions & 4 deletions packages/runtime/src/TokenGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@
* under the License.
*/

interface Token {
terminate(): void;
}

type TokenCountChangeListener = (kwargs: { count: number }) => void;

interface TokenGeneratorArgs {
onTokenCountChange: TokenCountChangeListener;
}

export default class TokenGenerator {
protected _tokenCount = 0;
protected _onTokenCountChange;
protected _onTokenCountChange: TokenCountChangeListener;

constructor({ onTokenCountChange }:{ onTokenCountChange:(_:{ count:number })=>void } = {}) {
constructor({ onTokenCountChange }: TokenGeneratorArgs) {
if (!onTokenCountChange) {
throw new Error(`TokenGenerator requires an onTokenCountChange listener to be passed in`);
}
Expand All @@ -31,7 +41,7 @@ export default class TokenGenerator {
*
* Call the returned terminate function when the task is complete.
*/
generateToken():{ terminate:()=>void } {
generateToken(): Token {
let terminated = false;
this._updateTokenCount(+1);

Expand All @@ -48,7 +58,7 @@ export default class TokenGenerator {
}
}

_updateTokenCount(delta:number):void {
_updateTokenCount(delta: number): void {
this._tokenCount += delta;
this._onTokenCountChange({ count: this._tokenCount });
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/__tests__/Scheduler-addPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Scheduler.addPlan',
() => {
scheduler.addPlan();
}
).to.throw(`Scheduler.addPlan requires`);
).to.throw();
}
);

Expand Down
12 changes: 11 additions & 1 deletion packages/runtime/src/__tests__/TokenGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,22 @@ describe('TokenGenerator',
() => {
let tokenGenerator;

it(`should require a callback`,
it(`should require arguments`,
() => {
expect(
() => {
new TokenGenerator();
}
).to.throw();
}
);

it(`should require an onTokenCountChange listener`,
() => {
expect(
() => {
new TokenGenerator({});
}
).to.throw(`onTokenCountChange`);
}
);
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"include": ["./src/**/*"],
"exclude": ["**/*.test.*"],
"compilerOptions": {
"lib": [
"es2015",
Expand All @@ -10,6 +12,7 @@
"noImplicitThis": true,
"outDir": "dist",
"sourceMap": true,
"strictNullChecks": true,
"target": "es6"
}
}

0 comments on commit 90b002c

Please sign in to comment.