Skip to content

Commit da05025

Browse files
author
Javier Morant
authored
Check if data prop has changed when new content is received (#56)
* Fix diff issue * Changed yarn.lock
1 parent e1a0d88 commit da05025

File tree

5 files changed

+60
-11
lines changed

5 files changed

+60
-11
lines changed

examples/yarn.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@
392392
lodash "^4.2.0"
393393
to-fast-properties "^2.0.0"
394394

395+
"@types/lodash.isequal@^4.5.2":
396+
version "4.5.2"
397+
resolved "https://registry.yarnpkg.com/@types/lodash.isequal/-/lodash.isequal-4.5.2.tgz#adbdff67f7c956ed703009e5466a34eeddb0b712"
398+
dependencies:
399+
"@types/lodash" "*"
400+
401+
"@types/lodash@*":
402+
version "4.14.106"
403+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.106.tgz#6093e9a02aa567ddecfe9afadca89e53e5dce4dd"
404+
395405
abbrev@1:
396406
version "1.1.0"
397407
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
@@ -2872,6 +2882,10 @@ lodash.isarray@^3.0.0:
28722882
version "3.0.4"
28732883
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
28742884

2885+
lodash.isequal@^4.5.0:
2886+
version "4.5.0"
2887+
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
2888+
28752889
lodash.keys@^3.0.0:
28762890
version "3.1.2"
28772891
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
@@ -3700,6 +3714,8 @@ react-native-drawer-layout@1.3.2:
37003714
"react-native-nested-listview@file:..":
37013715
version "0.3.0"
37023716
dependencies:
3717+
"@types/lodash.isequal" "^4.5.2"
3718+
lodash.isequal "^4.5.0"
37033719
shortid "^2.2.8"
37043720

37053721
react-native-safe-area-view@^0.7.0:

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"url": "git+https://github.com/fjmorant/react-native-nested-listview.git"
1717
},
1818
"dependencies": {
19+
"@types/lodash.isequal": "^4.5.2",
20+
"lodash.isequal": "^4.5.0",
1921
"shortid": "^2.2.8"
2022
},
2123
"peerDependencies": {
@@ -36,18 +38,23 @@
3638
"eslint-plugin-react": "^7.4.0",
3739
"eslint-plugin-react-native": "^3.1.0",
3840
"flow-bin": "^0.68.0",
39-
"jest": "^22.4.2",
4041
"istanbul": "^0.4.5",
4142
"istanbul-api": "1.2.2",
4243
"istanbul-reports": "1.1.4",
44+
"jest": "^22.4.2",
4345
"prettier": "^1.7.0",
4446
"prettier-eslint": "^8.2.1",
4547
"react-test-renderer": "16.2.0",
4648
"ts-jest": "^22.4.1",
4749
"tslint": "^5.9.1",
4850
"typescript": "^2.7.2"
4951
},
50-
"keywords": ["react", "native", "list", "nested"],
52+
"keywords": [
53+
"react",
54+
"native",
55+
"list",
56+
"nested"
57+
],
5158
"author": "Javier Morant",
5259
"license": "MIT",
5360
"bugs": {
@@ -56,7 +63,11 @@
5663
"homepage": "https://github.com/fjmorant/react-native-nested-listview#readme",
5764
"jest": {
5865
"preset": "react-native",
59-
"moduleFileExtensions": ["ts", "tsx", "js"],
66+
"moduleFileExtensions": [
67+
"ts",
68+
"tsx",
69+
"js"
70+
],
6071
"transform": {
6172
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
6273
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
@@ -65,7 +76,9 @@
6576
"node_modules/(?!(jest-)|react-native|react-navigation|react-clone-referenced-element|mobx-react)"
6677
],
6778
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
68-
"modulePathIgnorePatterns": ["<rootDir>/examples/"],
79+
"modulePathIgnorePatterns": [
80+
"<rootDir>/examples/"
81+
],
6982
"testPathIgnorePatterns": [
7083
"\\.snap$",
7184
"<rootDir>/node_modules/",

src/NestedListView.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22

3+
import isEqual from 'lodash.isequal'
34
import * as React from 'react'
45
import {StyleSheet, Text, View} from 'react-native'
56
import * as shortid from 'shortid'
@@ -42,7 +43,9 @@ export default class NestedListView extends React.PureComponent<
4243
}
4344

4445
public componentWillReceiveProps(nextProps: any) {
45-
this.setState({root: this.generateRootNode(nextProps)})
46+
if (!isEqual(this.props.data, nextProps.data)) {
47+
this.setState({root: this.generateRootNode(nextProps)})
48+
}
4649
}
4750

4851
public generateIds = (node?: INode) => {

src/NodeView.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* @flow */
22

3+
import isEqual from 'lodash.isequal'
34
import * as React from 'react'
45
import {FlatList, TouchableWithoutFeedback, View} from 'react-native'
56

@@ -36,12 +37,14 @@ export default class NodeView extends React.PureComponent<IProps, IState> {
3637
}
3738

3839
public componentWillReceiveProps(nextProps: IProps) {
39-
this.setState({
40-
node: {
41-
opened: false,
42-
...nextProps.node,
43-
},
44-
})
40+
if (!isEqual(this.props.node, nextProps.node)) {
41+
this.setState({
42+
node: {
43+
opened: false,
44+
...nextProps.node,
45+
},
46+
})
47+
}
4548
}
4649

4750
public onNodePressed = () => {

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@
8282
version "22.2.0"
8383
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-22.2.0.tgz#55ce83139f7ad1b48b414c3927746614c6963c0f"
8484

85+
"@types/lodash.isequal@^4.5.2":
86+
version "4.5.2"
87+
resolved "https://registry.yarnpkg.com/@types/lodash.isequal/-/lodash.isequal-4.5.2.tgz#adbdff67f7c956ed703009e5466a34eeddb0b712"
88+
dependencies:
89+
"@types/lodash" "*"
90+
91+
"@types/lodash@*":
92+
version "4.14.106"
93+
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.106.tgz#6093e9a02aa567ddecfe9afadca89e53e5dce4dd"
94+
8595
"@types/react-native@^0.52.17":
8696
version "0.52.18"
8797
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.52.18.tgz#082fada6fdddc6c745a4c1a6234e4aa3b104176b"
@@ -2887,6 +2897,10 @@ locate-path@^2.0.0:
28872897
p-locate "^2.0.0"
28882898
path-exists "^3.0.0"
28892899

2900+
lodash.isequal@^4.5.0:
2901+
version "4.5.0"
2902+
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
2903+
28902904
lodash.merge@^4.6.0:
28912905
version "4.6.1"
28922906
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.1.tgz#adc25d9cb99b9391c59624f379fbba60d7111d54"

0 commit comments

Comments
 (0)