Skip to content

Commit 186ea3e

Browse files
wclrstaltz
authored andcommitted
add and make prettier formatting
1 parent 5c71a2b commit 186ea3e

File tree

8 files changed

+65
-61
lines changed

8 files changed

+65
-61
lines changed

package.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"main": "lib/cjs/index.js",
1919
"typings": "lib/cjs/index.d.ts",
2020
"types": "lib/cjs/index.d.ts",
21+
"prettier": {
22+
"singleQuote": true,
23+
"trailingComma": "es5",
24+
"bracketSpacing": false
25+
},
2126
"peerDependencies": {
2227
"@cycle/run": "5.x.x",
2328
"react": "16.x.x",
@@ -30,6 +35,7 @@
3035
"@types/node": "^10.5.2",
3136
"@types/react": "16.9.49",
3237
"mocha": "^6.2.0",
38+
"prettier": "^2.1.2",
3339
"react": "16.13.1",
3440
"react-dom": "16.13.1",
3541
"react-test-renderer": "16.13.1",
@@ -42,10 +48,11 @@
4248
"access": "public"
4349
},
4450
"scripts": {
45-
"prepublishOnly": "npm run compile",
51+
"format": "prettier --write ./{src,test}/**/*.{ts,tsx,js}",
4652
"compile": "npm run compile-cjs && npm run compile-es6",
4753
"compile-cjs": "tsc --module commonjs --outDir ./lib/cjs",
4854
"compile-es6": "echo 'TODO' : tsc --module es6 --outDir ./lib/es6",
49-
"test": "$(npm bin)/mocha test/*.ts --require ts-node/register --recursive"
55+
"prepublishOnly": "npm run compile",
56+
"test": "mocha test/*.ts --require ts-node/register --recursive"
5057
}
5158
}

src/ReactSource.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ReactSource<P = any> {
1515
constructor(
1616
scope: Scope = new Scope(),
1717
selector: string | symbol | null = null,
18-
props$: MemoryStream<P> = xs.createWithMemory<P>(),
18+
props$: MemoryStream<P> = xs.createWithMemory<P>()
1919
) {
2020
this._scope = scope;
2121
this._selector = selector;
@@ -48,8 +48,8 @@ export class ReactSource<P = any> {
4848

4949
public isolateSink(sink: Sink, scopeId: string): Sink {
5050
const isolation = this.getChildScope(scopeId);
51-
return sink.map(elem =>
52-
createElement(ScopeContext.Provider, {value: isolation}, elem),
51+
return sink.map((elem) =>
52+
createElement(ScopeContext.Provider, {value: isolation}, elem)
5353
);
5454
}
5555

src/convert.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type State = {
2020
};
2121

2222
export function makeCycleReactComponent<P = any>(
23-
run: RunOnDidMount,
23+
run: RunOnDidMount
2424
): ComponentType<P> {
2525
return class CycleReactComponent extends PureComponent<P, State> {
2626
constructor(props: P) {
@@ -49,10 +49,10 @@ export function makeCycleReactComponent<P = any>(
4949
const handlerName = `on${name[0].toUpperCase()}${name.slice(1)}`;
5050
this._subs.push(
5151
events[name].subscribe({
52-
next: x => {
52+
next: (x) => {
5353
if (this.props[handlerName]) this.props[handlerName](x);
5454
},
55-
}),
55+
})
5656
);
5757
}
5858
}
@@ -63,7 +63,7 @@ export function makeCycleReactComponent<P = any>(
6363
return createElement(
6464
ScopeContext.Provider,
6565
{value: source._scope},
66-
createElement(StreamRenderer, {stream: sink}),
66+
createElement(StreamRenderer, {stream: sink})
6767
);
6868
}
6969

@@ -89,7 +89,7 @@ export function makeComponent<
8989
>(
9090
main: MatchingMain<D, M>,
9191
drivers: MatchingDrivers<D, M> = null as any,
92-
channel: string = 'react',
92+
channel: string = 'react'
9393
): ComponentType<P> {
9494
if (drivers) {
9595
return makeCycleReactComponent<P>(() => {

src/h.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Children = string | Array<ReactNode>;
1919
function createElementSpreading<P = any>(
2020
type: ElementType<P> | keyof ReactHTML,
2121
props: PropsLike<P> | null,
22-
children: Children,
22+
children: Children
2323
): ReactElement<P> {
2424
if (typeof children === 'string') {
2525
return createElement(type, props, children);
@@ -30,7 +30,7 @@ function createElementSpreading<P = any>(
3030

3131
function hyperscriptProps<P = any>(
3232
type: ElementType<P> | keyof ReactHTML,
33-
props: PropsLike<P>,
33+
props: PropsLike<P>
3434
): ReactElement<P> {
3535
if (!props.sel) {
3636
return createElement(type, props);
@@ -41,15 +41,15 @@ function hyperscriptProps<P = any>(
4141

4242
function hyperscriptChildren<P = any>(
4343
type: ElementType<P> | keyof ReactHTML,
44-
children: Children,
44+
children: Children
4545
): ReactElement<P> {
4646
return createElementSpreading(type, null, children);
4747
}
4848

4949
function hyperscriptPropsChildren<P = any>(
5050
type: ElementType<P> | keyof ReactHTML,
5151
props: PropsLike<P>,
52-
children: Children,
52+
children: Children
5353
): ReactElement<P> {
5454
if (!props.sel) {
5555
return createElementSpreading(type, props, children);
@@ -61,7 +61,7 @@ function hyperscriptPropsChildren<P = any>(
6161
export function h<P = any>(
6262
type: ElementType<P> | keyof ReactHTML,
6363
a?: PropsLike<P> | Children,
64-
b?: Children,
64+
b?: Children
6565
): ReactElement<P> {
6666
if (a === undefined && b === undefined) {
6767
return createElement(type, null);

src/incorporate.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function incorporate(type: any) {
1616
targetRef: ref,
1717
target: type,
1818
scope: scope,
19-
}),
20-
),
21-
),
19+
})
20+
)
21+
)
2222
);
2323
}
2424
return wrapperComponents.get(type) as React.ComponentType<any>;

test/api.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Findable extends PureComponent<any, any> {
1616
}
1717
}
1818

19-
describe('API', function() {
20-
it('makeCycleReactComponent', function(done) {
19+
describe('API', function () {
20+
it('makeCycleReactComponent', function (done) {
2121
function main(sources: {react: ReactSource}) {
2222
return {
2323
react: xs
@@ -26,7 +26,7 @@ describe('API', function() {
2626
.map(() =>
2727
h(Findable, {sel: 'ya'}, [
2828
h('div', {}, [h('h1', {}, 'Hello world')]),
29-
]),
29+
])
3030
),
3131
};
3232
}
@@ -47,7 +47,7 @@ describe('API', function() {
4747
}, 50);
4848
});
4949

50-
it('makeComponent from main, drivers, and channel', function(done) {
50+
it('makeComponent from main, drivers, and channel', function (done) {
5151
function main(sources: {foobar: ReactSource}) {
5252
return {
5353
foobar: xs
@@ -56,7 +56,7 @@ describe('API', function() {
5656
.map(() =>
5757
h(Findable, {sel: 'ya'}, [
5858
h('div', {}, [h('h1', {}, 'Hello world')]),
59-
]),
59+
])
6060
),
6161
};
6262
}
@@ -73,7 +73,7 @@ describe('API', function() {
7373
}, 50);
7474
});
7575

76-
it('makeComponent from main (no drivers, no channel)', function(done) {
76+
it('makeComponent from main (no drivers, no channel)', function (done) {
7777
function main(sources: {react: ReactSource}) {
7878
return {
7979
react: xs
@@ -82,7 +82,7 @@ describe('API', function() {
8282
.map(() =>
8383
h(Findable, {sel: 'ya'}, [
8484
h('div', {}, [h('h1', {}, 'Hello world')]),
85-
]),
85+
])
8686
),
8787
};
8888
}

test/conversion.ts

+20-23
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class Touchable extends PureComponent<any, any> {
1717
}
1818
}
1919

20-
describe('Conversion', function() {
21-
it('converts an MVI Cycle app into a React component', done => {
20+
describe('Conversion', function () {
21+
it('converts an MVI Cycle app into a React component', (done) => {
2222
function main(sources: {react: ReactSource}) {
2323
const inc$ = sources.react.select('button').events('press');
2424
const count$ = inc$.fold((acc: number, x: any) => acc + 1, 0);
2525
const vdom$ = count$.map((i: number) =>
26-
h(Touchable, {sel: 'button'}, [h('div', [h('h1', {}, '' + i)])]),
26+
h(Touchable, {sel: 'button'}, [h('div', [h('h1', {}, '' + i)])])
2727
);
2828
return {react: vdom$};
2929
}
@@ -52,13 +52,13 @@ describe('Conversion', function() {
5252
setTimeout(check, 150);
5353
});
5454

55-
it('allows Symbol selectors', done => {
55+
it('allows Symbol selectors', (done) => {
5656
function main(sources: {react: ReactSource}) {
5757
const inc = Symbol();
5858
const inc$ = sources.react.select(inc).events('press');
5959
const count$ = inc$.fold((acc: number, x: any) => acc + 1, 0);
6060
const vdom$ = count$.map((i: number) =>
61-
h(Touchable, {sel: inc}, [h('div', [h('h1', {}, '' + i)])]),
61+
h(Touchable, {sel: inc}, [h('div', [h('h1', {}, '' + i)])])
6262
);
6363
return {react: vdom$};
6464
}
@@ -87,10 +87,10 @@ describe('Conversion', function() {
8787
setTimeout(check, 150);
8888
});
8989

90-
it('output React component routes props to sources.react.props()', done => {
90+
it('output React component routes props to sources.react.props()', (done) => {
9191
function main(sources: {react: ReactSource}) {
9292
sources.react.props().addListener({
93-
next: props => {
93+
next: (props) => {
9494
assert.strictEqual(props.name, 'Alice');
9595
assert.strictEqual(props.age, 30);
9696
done();
@@ -99,7 +99,7 @@ describe('Conversion', function() {
9999

100100
return {
101101
react: xs.of(
102-
h('section', [h('div', {}, [h('h1', {}, 'Hello world')])]),
102+
h('section', [h('div', {}, [h('h1', {}, 'Hello world')])])
103103
),
104104
};
105105
}
@@ -112,16 +112,13 @@ describe('Conversion', function() {
112112
renderer.create(createElement(RootComponent, {name: 'Alice', age: 30}));
113113
});
114114

115-
it('output React component routes other sinks to handlers in props', done => {
115+
it('output React component routes other sinks to handlers in props', (done) => {
116116
function main(sources: {react: ReactSource}) {
117117
return {
118118
react: xs.of(
119-
h('section', [h('div', {}, [h('h1', {}, 'Hello world')])]),
119+
h('section', [h('div', {}, [h('h1', {}, 'Hello world')])])
120120
),
121-
something: xs
122-
.periodic(200)
123-
.mapTo('yellow')
124-
.take(1),
121+
something: xs.periodic(200).mapTo('yellow').take(1),
125122
};
126123
}
127124

@@ -133,22 +130,22 @@ describe('Conversion', function() {
133130
});
134131
renderer.create(
135132
createElement(RootComponent, {
136-
onSomething: x => {
133+
onSomething: (x) => {
137134
assert.strictEqual(x, 'yellow');
138135
done();
139136
},
140-
}),
137+
})
141138
);
142139
});
143140

144-
it('sources.react.props() evolves over time as new props come in', done => {
141+
it('sources.react.props() evolves over time as new props come in', (done) => {
145142
function main(sources: {react: ReactSource}) {
146143
let first = false;
147144
sources.react
148145
.props()
149146
.take(1)
150147
.addListener({
151-
next: props => {
148+
next: (props) => {
152149
assert.strictEqual(props.name, 'Alice');
153150
assert.strictEqual(props.age, 30);
154151
first = true;
@@ -160,7 +157,7 @@ describe('Conversion', function() {
160157
.drop(1)
161158
.take(1)
162159
.addListener({
163-
next: props => {
160+
next: (props) => {
164161
assert.strictEqual(first, true);
165162
assert.strictEqual(props.name, 'alice');
166163
assert.strictEqual(props.age, 31);
@@ -170,7 +167,7 @@ describe('Conversion', function() {
170167

171168
return {
172169
react: xs.of(
173-
h('section', [h('div', {}, [h('h1', {}, 'Hello world')])]),
170+
h('section', [h('div', {}, [h('h1', {}, 'Hello world')])])
174171
),
175172
};
176173
}
@@ -181,12 +178,12 @@ describe('Conversion', function() {
181178
return {source, sink};
182179
});
183180
const r = renderer.create(
184-
createElement(RootComponent, {name: 'Alice', age: 30}),
181+
createElement(RootComponent, {name: 'Alice', age: 30})
185182
);
186183
r.update(createElement(RootComponent, {name: 'alice', age: 31}));
187184
});
188185

189-
it('no synchronous race conditions with handler registration', done => {
186+
it('no synchronous race conditions with handler registration', (done) => {
190187
function main(sources: {react: ReactSource}) {
191188
const inc$ = xs.create({
192189
start(listener: any) {
@@ -201,7 +198,7 @@ describe('Conversion', function() {
201198
});
202199
const count$ = inc$.fold((acc: number, x: any) => acc + 1, 0);
203200
const vdom$ = count$.map((i: number) =>
204-
h(Touchable, {sel: 'button'}, [h('div', [h('h1', {}, '' + i)])]),
201+
h(Touchable, {sel: 'button'}, [h('div', [h('h1', {}, '' + i)])])
205202
);
206203
return {react: vdom$};
207204
}

0 commit comments

Comments
 (0)