Skip to content

Commit 93f716c

Browse files
committed
style(core): use prettify to formating
1 parent 6c57483 commit 93f716c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+667
-997
lines changed

benchmarks/bm.combine.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@ const c = array(1e2)
1313
const sum3 = (a: number, b: number, c: number) => a + b + c
1414
const sum2 = (a: number, b: number) => a + b
1515

16-
export function bm_fromArray_combine (suite: Suite) {
17-
return suite
18-
.add(
19-
'file -> combine(sum3, [a, b, c]) -> reduce(sum2, 0)',
20-
(d: IDeferred) => run(
21-
reduce(sum2, 0, combine(sum3, [fromArray(a), fromArray(b), fromArray(c)])),
22-
d
23-
),
24-
{defer: true}
25-
)
16+
export function bm_fromArray_combine(suite: Suite) {
17+
return suite.add(
18+
'file -> combine(sum3, [a, b, c]) -> reduce(sum2, 0)',
19+
(d: IDeferred) => run(reduce(sum2, 0, combine(sum3, [fromArray(a), fromArray(b), fromArray(c)])), d),
20+
{defer: true}
21+
)
2622
}

benchmarks/bm.create.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ import {IObserver} from '../src/lib/Observer'
66
import {create} from '../src/sources/Create'
77
import {IDeferred, run} from './lib'
88

9-
function subscriber (observer: IObserver<number>) {
9+
function subscriber(observer: IObserver<number>) {
1010
for (var i = 0; i < 1e6; ++i) {
1111
observer.next(i)
1212
}
1313
observer.complete()
1414
}
1515

16-
export function bm_create (suite: Suite) {
17-
return suite.add(
18-
'create',
19-
(d: IDeferred) => run(create(subscriber), d),
20-
{defer: true}
21-
)
16+
export function bm_create(suite: Suite) {
17+
return suite.add('create', (d: IDeferred) => run(create(subscriber), d), {defer: true})
2218
}

benchmarks/bm.debounce.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import {fromArray} from '../src/sources/FromArray'
77
import {array, IDeferred, run} from './lib'
88

99
const a = array(1e3)
10-
export function bm_debounce (suite: Suite) {
11-
return suite.add(
12-
'file -> debounce',
13-
(d: IDeferred) => run(debounce(100, fromArray(a)), d),
14-
{defer: true}
15-
)
10+
export function bm_debounce(suite: Suite) {
11+
return suite.add('file -> debounce', (d: IDeferred) => run(debounce(100, fromArray(a)), d), {defer: true})
1612
}

benchmarks/bm.fromArray-map-reduce.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Created by tushar.mathur on 05/11/16.
33
*/
44

5-
65
import {Suite} from 'benchmark'
76
import {filter} from '../src/operators/Filter'
87
import {map} from '../src/operators/Map'
@@ -11,7 +10,7 @@ import {fromArray} from '../src/sources/FromArray'
1110
import {add1, array, even, IDeferred, run, sum} from './lib'
1211

1312
const a = array(1e6)
14-
export function bm_fromArray_map_reduce (suite: Suite) {
13+
export function bm_fromArray_map_reduce(suite: Suite) {
1514
return suite.add(
1615
'file -> map -> reduce',
1716
(d: IDeferred) => run(reduce(sum, 0, map(add1, filter(even, fromArray(a)))), d),

benchmarks/bm.fromArray-scan-reduce.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
* Created by tushar.mathur on 05/11/16.
33
*/
44

5-
65
import {Suite} from 'benchmark'
76
import {reduce} from '../src/operators/Reduce'
87
import {scan} from '../src/operators/Scan'
98
import {fromArray} from '../src/sources/FromArray'
109
import {array, IDeferred, passthrough, run, sum} from './lib'
1110

1211
const a = array(1e6)
13-
export function bm_fromArray_scan_reduce (suite: Suite) {
12+
export function bm_fromArray_scan_reduce(suite: Suite) {
1413
return suite.add(
1514
'file -> scan -> reduce',
1615
(d: IDeferred) => run(reduce(passthrough, 0, scan(sum, 0, fromArray(a))), d),

benchmarks/bm.fromArray-takeN.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import {fromArray} from '../src/sources/FromArray'
88
import {array, IDeferred, run} from './lib'
99

1010
const a = array(1e6)
11-
export function bm_fromArray_takeN (suite: Suite) {
12-
return suite
13-
.add(
14-
'file -> takeN(0, n/10)',
15-
(d: IDeferred) => run(slice(0, 1e6 / 10, fromArray(a)), d),
16-
{defer: true}
17-
)
11+
export function bm_fromArray_takeN(suite: Suite) {
12+
return suite.add('file -> takeN(0, n/10)', (d: IDeferred) => run(slice(0, 1e6 / 10, fromArray(a)), d), {defer: true})
1813
}

benchmarks/bm.switch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import {array, IDeferred, run} from './lib'
99

1010
const a = array(1e2)
1111

12-
export function bm_switch (suite: Suite) {
12+
export function bm_switch(suite: Suite) {
1313
return suite.add(
1414
'array(2) -> array(i) -> switchLatest',
15-
(d: IDeferred) => run(switchLatest(map((i) => fromArray(array(i)), fromArray(a))), d),
15+
(d: IDeferred) => run(switchLatest(map(i => fromArray(array(i)), fromArray(a))), d),
1616
{defer: true}
1717
)
1818
}

benchmarks/bm.tryCatch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Suite} from 'benchmark'
55
import {ISafeValue, tryCatch} from '../src/lib/Utils'
66
import {array} from './lib'
77

8-
function addThis (b: number) {
8+
function addThis(b: number) {
99
this.a = this.a + b
1010
if (this.a % 2 === 0) {
1111
throw 'ERROR'
@@ -14,14 +14,14 @@ function addThis (b: number) {
1414
}
1515
const safelyAddThis = tryCatch(addThis)
1616

17-
export function testFunction (arr: number[]): Array<ISafeValue<any>> {
17+
export function testFunction(arr: number[]): Array<ISafeValue<any>> {
1818
const results = []
1919
for (var i = 0; i < arr.length; ++i) {
2020
results.push(safelyAddThis.call({a: 100}, i))
2121
}
2222
return results
2323
}
2424
const arr = array(1e3)
25-
export function bm_tryCatch (suite: Suite) {
25+
export function bm_tryCatch(suite: Suite) {
2626
return suite.add('tryCatch', () => testFunction(arr))
2727
}

benchmarks/lib.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,46 @@ import {createScheduler, IScheduler} from '../src/lib/Scheduler'
66
* Created by tushar.mathur on 05/11/16.
77
*/
88

9-
109
const Table = require('cli-table2')
1110

12-
1311
export interface IDeferred {
14-
resolve (): void
12+
resolve(): void
1513
}
16-
export function add1 (x: number) {
14+
export function add1(x: number) {
1715
return x + 1
1816
}
19-
export function even (e: number) {
17+
export function even(e: number) {
2018
return e % 2 === 0
2119
}
22-
export function sum (a: number, b: number) {
20+
export function sum(a: number, b: number) {
2321
return a + b
2422
}
2523

26-
export function passthrough (z: any, x: any) {
24+
export function passthrough(z: any, x: any) {
2725
return x
2826
}
2927

3028
export const scheduler = createScheduler() as IScheduler
3129

3230
class BmObserver<T> implements IObserver<T> {
33-
constructor (private d: IDeferred) {}
31+
constructor(private d: IDeferred) {}
3432

35-
next (val: T): void {
36-
}
33+
next(val: T): void {}
3734

38-
error (err: Error): void {
35+
error(err: Error): void {
3936
throw err
4037
}
4138

42-
complete (): void {
39+
complete(): void {
4340
this.d.resolve()
4441
}
4542
}
4643

47-
export function run (observable: IObservable<any>, d: IDeferred) {
48-
observable.subscribe(new BmObserver(d), scheduler
49-
)
44+
export function run(observable: IObservable<any>, d: IDeferred) {
45+
observable.subscribe(new BmObserver(d), scheduler)
5046
}
5147

52-
export function array (n: number) {
48+
export function array(n: number) {
5349
const a = new Array(n)
5450
for (var i = 0; i < a.length; ++i) {
5551
a[i] = i
@@ -66,7 +62,7 @@ export const onCycle = (event: any) => {
6662
table.push([
6763
target.name,
6864
`${Math.floor(target.hz).toLocaleString()}${Math.round(target.stats.rme * 100) / 100}%)`,
69-
target.stats.sample.length,
65+
target.stats.sample.length
7066
])
7167
}
7268

@@ -75,4 +71,3 @@ export const onEnd = () => {
7571
console.log(table.toString())
7672
console.log('```')
7773
}
78-

benchmarks/run.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,4 @@ bm_fromArray_scan_reduce(suite)
2626
bm_fromArray_takeN(suite)
2727
bm_switch(suite)
2828
bm_tryCatch(suite)
29-
suite
30-
.on('cycle', onCycle)
31-
.on('complete', onEnd)
32-
.run()
29+
suite.on('cycle', onCycle).on('complete', onEnd).run()

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"test": "tsc && ava",
1515
"test:watch": "ava --watch",
1616
"build": "rollup -c ./config/rollup.config.js",
17-
"lint": "git ls-files | grep '.ts$' | xargs tslint"
17+
"lint": "git ls-files | grep '.ts$' | xargs tslint",
18+
"prettify": "git ls-files | grep '.ts$' | xargs prettier --print-width 120 --write --single-quote --no-semi --no-bracket-spacing"
1819
},
1920
"author": "",
2021
"license": "ISC",
@@ -28,6 +29,7 @@
2829
"gh-pages": "^1.0.0",
2930
"ghooks": "^2.0.0",
3031
"nyc": "^10.0.0",
32+
"prettify": "^0.1.7",
3133
"request-promise": "^4.1.1",
3234
"rollup": "^0.41.2",
3335
"rollup-plugin-babili": "^3.0.0",

src/lib/Container.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
* Created by tushar on 08/12/16.
33
*/
44

5-
export enum StreamStatus { IDLE, STARTED, COMPLETED }
5+
export enum StreamStatus {
6+
IDLE,
7+
STARTED,
8+
COMPLETED
9+
}
610

7-
export function createArray<T> (size: number, value: T) {
11+
export function createArray<T>(size: number, value: T) {
812
const arr: Array<T> = new Array(size)
913
for (var i = 0; i < size; ++i) {
1014
arr[i] = value
@@ -13,7 +17,7 @@ export function createArray<T> (size: number, value: T) {
1317
}
1418

1519
export interface IContainer {
16-
next<T> (value: T, id: number): void
20+
next<T>(value: T, id: number): void
1721
complete(id: number): boolean
1822
isDone(): boolean
1923
isOn(): boolean
@@ -26,30 +30,29 @@ class ValueContainer implements IContainer {
2630
private started = 0
2731
private completed = 0
2832

29-
constructor (private total: number) {
30-
}
33+
constructor(private total: number) {}
3134

32-
next (value: any, id: number) {
35+
next(value: any, id: number) {
3336
if (this.status[id] === StreamStatus.IDLE) {
3437
this.status[id] = StreamStatus.STARTED
3538
this.started++
3639
}
3740
this.values[id] = value
3841
}
3942

40-
complete (id: number) {
43+
complete(id: number) {
4144
if (this.status[id] !== StreamStatus.COMPLETED) {
4245
this.status[id] = StreamStatus.COMPLETED
4346
this.completed++
4447
}
4548
return this.isDone()
4649
}
4750

48-
isDone () {
51+
isDone() {
4952
return this.completed === this.total
5053
}
5154

52-
isOn () {
55+
isOn() {
5356
return this.started === this.total
5457
}
5558
}

src/lib/ForEach.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@ export type TOnNext<T> = {(value: T): void}
1010
export type TSource<T> = IObservable<T>
1111
export type TResult = ISubscription
1212

13-
export const forEach = curry(function <T> (onNext: TOnNext<T>, observable: TSource<T>) {
14-
return observable.subscribe({
15-
next (value: T) {
16-
onNext(value)
13+
export const forEach = curry(function<T>(onNext: TOnNext<T>, observable: TSource<T>) {
14+
return observable.subscribe(
15+
{
16+
next(value: T) {
17+
onNext(value)
18+
},
19+
complete() {},
20+
error(err: Error) {
21+
throw err
22+
}
1723
},
18-
complete() {
19-
},
20-
error (err: Error) {
21-
throw err
22-
}
23-
}, createScheduler())
24-
}) as Function &
25-
{<T> (onNext: TOnNext<T>, source: TSource<T>): TResult} &
26-
{<T> (onNext: TOnNext<T>): {(source: TSource<T>): TResult}}
27-
24+
createScheduler()
25+
)
26+
}) as Function & {<T>(onNext: TOnNext<T>, source: TSource<T>): TResult} & {
27+
<T>(onNext: TOnNext<T>): {(source: TSource<T>): TResult}
28+
}

0 commit comments

Comments
 (0)