Skip to content

Commit 63b7b08

Browse files
author
Javier Morant
authored
Support Typescript (#46)
* Ignore coverage folder * Initial conversion to TS * Fix tests * Ignore only react-native module * Use a newer version of node * codecov included * Fix tests * Fix issue * Set workspace * Fix config * Fix circleci * fix circleci * pass ci arg in jest * Fix issue * fix issue * ignore test * Fix tests * configure tslint * Fix ts issue * Fix tests * Change peer dependency * Fix reports * Regenerate yarn.lock file
1 parent 5f6a154 commit 63b7b08

File tree

10 files changed

+3340
-975
lines changed

10 files changed

+3340
-975
lines changed

.circleci/config.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ version: 2
22
jobs:
33
build:
44
docker:
5-
- image: circleci/node:7.10.0
5+
- image: circleci/node:8.8.1
6+
working_directory: /home/circleci/rosetta
67
steps:
78
- checkout
89
- run: yarn install
910
- run: yarn add react@16.2.0
1011
- run: yarn add react-native@0.52.0
1112
- run: yarn add codecov
1213
- run: yarn lint
13-
- run: yarn flow
14+
- run: yarn tslint
15+
- run: yarn type-check
1416
- run: yarn test

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
coverage/
3+
4+
# TypeScript
5+
#
6+
lib/
7+
8+
# Jest
9+
#
10+
.jest/

NodeView.js renamed to NodeView.tsx

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
/* @flow */
22

3-
import React from 'react'
4-
import {
5-
TouchableWithoutFeedback,
6-
View,
7-
FlatList,
8-
type Props,
9-
type State,
10-
} from 'react-native'
3+
import * as React from 'react'
4+
import {FlatList, TouchableWithoutFeedback, View} from 'react-native'
115

12-
export type Node = {
13-
id: string,
14-
hidden: boolean,
15-
opened: boolean,
6+
export interface INode {
7+
id: string
8+
hidden: boolean
9+
opened: boolean
10+
[key: string]: any
1611
}
1712

18-
export default class NodeView extends React.PureComponent<Props, State> {
19-
props: {
20-
generateIds: Function,
21-
getChildren: Function,
22-
getChildrenName: Function,
23-
node: Node,
24-
level: number,
25-
onNodePressed: Function,
26-
renderNode: Function,
27-
renderChildrenNode: Function,
28-
}
13+
export interface IProps {
14+
generateIds?: (node?: INode) => any
15+
getChildren?: () => any
16+
getChildrenName: (item: INode) => any
17+
node: INode
18+
level: number
19+
onNodePressed?: (item: any) => any
20+
renderNode: (item: any, level: number) => any
21+
renderChildrenNode?: (item: any) => any
22+
}
23+
24+
export interface IState {
25+
node: INode
26+
}
2927

30-
componentWillMount = () => {
28+
export default class NodeView extends React.PureComponent<IProps, IState> {
29+
public componentWillMount() {
3130
this.setState({
3231
node: {
3332
opened: false,
@@ -36,7 +35,7 @@ export default class NodeView extends React.PureComponent<Props, State> {
3635
})
3736
}
3837

39-
onNodePressed = () => {
38+
public onNodePressed = () => {
4039
this.setState({
4140
node: {
4241
...this.state.node,
@@ -49,7 +48,7 @@ export default class NodeView extends React.PureComponent<Props, State> {
4948
}
5049
}
5150

52-
renderChildren = (item: Node, level: number) => {
51+
public renderChildren = (item: INode, level: number): any => {
5352
return (
5453
<NodeView
5554
getChildrenName={this.props.getChildrenName}
@@ -61,10 +60,10 @@ export default class NodeView extends React.PureComponent<Props, State> {
6160
)
6261
}
6362

64-
renderItem = ({item}: {item: Node}) =>
63+
public renderItem = ({item}: {item: INode}) =>
6564
this.renderChildren(item, this.props.level)
6665

67-
render() {
66+
public render() {
6867
const rootChildrenName = this.props.getChildrenName(this.state.node)
6968
const rootChildren = this.state.node[rootChildrenName]
7069

@@ -81,7 +80,7 @@ export default class NodeView extends React.PureComponent<Props, State> {
8180
<FlatList
8281
data={rootChildren}
8382
renderItem={this.renderItem}
84-
keyExtractor={item => item.id}
83+
keyExtractor={(item: INode) => item.id}
8584
/>
8685
) : null}
8786
</View>

__snapshots__/index.test.js.snap renamed to __snapshots__/index.test.tsx.snap

Lines changed: 15 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ exports[`NestedListView renders with nested arrays 1`] = `
249249
accessible={true}
250250
allowFontScaling={true}
251251
ellipsizeMode="tail"
252-
>
253-
node.name
254-
</Text>
252+
/>
255253
</View>
256254
</View>
257255
</View>
@@ -283,9 +281,7 @@ exports[`NestedListView renders with nested arrays 1`] = `
283281
accessible={true}
284282
allowFontScaling={true}
285283
ellipsizeMode="tail"
286-
>
287-
node.name
288-
</Text>
284+
/>
289285
</View>
290286
</View>
291287
</View>
@@ -317,9 +313,7 @@ exports[`NestedListView renders with nested arrays 1`] = `
317313
accessible={true}
318314
allowFontScaling={true}
319315
ellipsizeMode="tail"
320-
>
321-
node.name
322-
</Text>
316+
/>
323317
</View>
324318
</View>
325319
</View>
@@ -414,9 +408,7 @@ exports[`NestedListView renders with nested arrays and children with different n
414408
accessible={true}
415409
allowFontScaling={true}
416410
ellipsizeMode="tail"
417-
>
418-
node.name
419-
</Text>
411+
/>
420412
</View>
421413
</View>
422414
</View>
@@ -448,9 +440,7 @@ exports[`NestedListView renders with nested arrays and children with different n
448440
accessible={true}
449441
allowFontScaling={true}
450442
ellipsizeMode="tail"
451-
>
452-
node.name
453-
</Text>
443+
/>
454444
</View>
455445
</View>
456446
</View>
@@ -482,9 +472,7 @@ exports[`NestedListView renders with nested arrays and children with different n
482472
accessible={true}
483473
allowFontScaling={true}
484474
ellipsizeMode="tail"
485-
>
486-
node.name
487-
</Text>
475+
/>
488476
</View>
489477
</View>
490478
</View>
@@ -578,9 +566,7 @@ exports[`NestedListView renders with nested arrays and children with different t
578566
accessible={true}
579567
allowFontScaling={true}
580568
ellipsizeMode="tail"
581-
>
582-
node.name
583-
</Text>
569+
/>
584570
</View>
585571
</View>
586572
</View>
@@ -612,9 +598,7 @@ exports[`NestedListView renders with nested arrays and children with different t
612598
accessible={true}
613599
allowFontScaling={true}
614600
ellipsizeMode="tail"
615-
>
616-
node.name
617-
</Text>
601+
/>
618602
</View>
619603
</View>
620604
</View>
@@ -646,9 +630,7 @@ exports[`NestedListView renders with nested arrays and children with different t
646630
accessible={true}
647631
allowFontScaling={true}
648632
ellipsizeMode="tail"
649-
>
650-
node.name
651-
</Text>
633+
/>
652634
</View>
653635
</View>
654636
</View>
@@ -727,9 +709,7 @@ exports[`NestedListView renders with onNodePressed 1`] = `
727709
accessible={true}
728710
allowFontScaling={true}
729711
ellipsizeMode="tail"
730-
>
731-
node.name
732-
</Text>
712+
/>
733713
</View>
734714
</View>
735715
</View>
@@ -761,9 +741,7 @@ exports[`NestedListView renders with onNodePressed 1`] = `
761741
accessible={true}
762742
allowFontScaling={true}
763743
ellipsizeMode="tail"
764-
>
765-
node.name
766-
</Text>
744+
/>
767745
</View>
768746
</View>
769747
</View>
@@ -795,9 +773,7 @@ exports[`NestedListView renders with onNodePressed 1`] = `
795773
accessible={true}
796774
allowFontScaling={true}
797775
ellipsizeMode="tail"
798-
>
799-
node.name
800-
</Text>
776+
/>
801777
</View>
802778
</View>
803779
</View>
@@ -876,9 +852,7 @@ exports[`NestedListView renders with simple array 1`] = `
876852
accessible={true}
877853
allowFontScaling={true}
878854
ellipsizeMode="tail"
879-
>
880-
node.name
881-
</Text>
855+
/>
882856
</View>
883857
</View>
884858
</View>
@@ -910,9 +884,7 @@ exports[`NestedListView renders with simple array 1`] = `
910884
accessible={true}
911885
allowFontScaling={true}
912886
ellipsizeMode="tail"
913-
>
914-
node.name
915-
</Text>
887+
/>
916888
</View>
917889
</View>
918890
</View>
@@ -944,9 +916,7 @@ exports[`NestedListView renders with simple array 1`] = `
944916
accessible={true}
945917
allowFontScaling={true}
946918
ellipsizeMode="tail"
947-
>
948-
node.name
949-
</Text>
919+
/>
950920
</View>
951921
</View>
952922
</View>
@@ -955,99 +925,3 @@ exports[`NestedListView renders with simple array 1`] = `
955925
</RCTScrollView>
956926
</View>
957927
`;
958-
959-
exports[`NestedListView renders without data 1`] = `
960-
<View
961-
style={
962-
Object {
963-
"alignItems": "center",
964-
"backgroundColor": "rgb(237, 57, 40)",
965-
"borderColor": "rgb(84, 85, 86)",
966-
"borderWidth": 1,
967-
"height": 60,
968-
"justifyContent": "center",
969-
}
970-
}
971-
>
972-
<Text
973-
accessible={true}
974-
allowFontScaling={true}
975-
ellipsizeMode="tail"
976-
style={
977-
Object {
978-
"color": "rgb(255, 255, 255)",
979-
"fontSize": 17,
980-
"fontWeight": "bold",
981-
}
982-
}
983-
>
984-
prop
985-
data
986-
has not been passed
987-
</Text>
988-
</View>
989-
`;
990-
991-
exports[`NestedListView renders without getChildrenName 1`] = `
992-
<View
993-
style={
994-
Object {
995-
"alignItems": "center",
996-
"backgroundColor": "rgb(237, 57, 40)",
997-
"borderColor": "rgb(84, 85, 86)",
998-
"borderWidth": 1,
999-
"height": 60,
1000-
"justifyContent": "center",
1001-
}
1002-
}
1003-
>
1004-
<Text
1005-
accessible={true}
1006-
allowFontScaling={true}
1007-
ellipsizeMode="tail"
1008-
style={
1009-
Object {
1010-
"color": "rgb(255, 255, 255)",
1011-
"fontSize": 17,
1012-
"fontWeight": "bold",
1013-
}
1014-
}
1015-
>
1016-
prop
1017-
getChildrenName
1018-
has not been passed
1019-
</Text>
1020-
</View>
1021-
`;
1022-
1023-
exports[`NestedListView renders without renderNode 1`] = `
1024-
<View
1025-
style={
1026-
Object {
1027-
"alignItems": "center",
1028-
"backgroundColor": "rgb(237, 57, 40)",
1029-
"borderColor": "rgb(84, 85, 86)",
1030-
"borderWidth": 1,
1031-
"height": 60,
1032-
"justifyContent": "center",
1033-
}
1034-
}
1035-
>
1036-
<Text
1037-
accessible={true}
1038-
allowFontScaling={true}
1039-
ellipsizeMode="tail"
1040-
style={
1041-
Object {
1042-
"color": "rgb(255, 255, 255)",
1043-
"fontSize": 17,
1044-
"fontWeight": "bold",
1045-
}
1046-
}
1047-
>
1048-
prop
1049-
renderNode
1050-
has not been passed
1051-
</Text>
1052-
</View>
1053-
`;

0 commit comments

Comments
 (0)