Skip to content

Commit f8b8230

Browse files
committed
📝 Update and simplify the README
1 parent e4e4335 commit f8b8230

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

README.md

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55
[![npm version](https://img.shields.io/npm/v/react-native-immutable-list-view.svg)](https://www.npmjs.com/package/react-native-immutable-list-view)
66
[![Latest GitHub tag](https://img.shields.io/github/tag/cooperka/react-native-immutable-list-view.svg)](https://github.com/cooperka/react-native-immutable-list-view)
77

8-
A drop-in replacement for React Native's `ListView`.
8+
A drop-in replacement for React Native's [`ListView`](https://facebook.github.io/react-native/docs/listview.html).
99

10-
It supports [Immutable](https://facebook.github.io/immutable-js/) data out-of-the-box to give you faster performance :racehorse: and less headaches :face_with_head_bandage:.
10+
It supports [Immutable](https://facebook.github.io/immutable-js/) data out-of-the-box to give you
11+
faster performance :racehorse: and less headaches :face_with_head_bandage:.
12+
13+
## Code
14+
15+
```jsx
16+
<ImmutableListView
17+
immutableData={this.state.listData}
18+
renderRow={this.renderRow}
19+
/>
20+
```
1121

1222
## Motivation
1323

@@ -17,35 +27,40 @@ It supports [Immutable](https://facebook.github.io/immutable-js/) data out-of-th
1727
- Do you have nested objects in your state so a shallow diff won't cut it for pure rendering?
1828
- Do you use a navigator and want better performance while animating?
1929

20-
If you answered yes to ANY of these questions, this project will surely be of help. Check out the examples below!
30+
If you answered yes to ANY of these questions, this project will surely help.
31+
Check out the [examples](https://github.com/cooperka/react-native-immutable-list-view#how-to-format-your-data) below!
2132

22-
## Setup
33+
## Usage
2334

24-
```console
25-
npm install --save react-native-immutable-list-view
26-
```
35+
1. Install:
36+
- Using [npm](https://www.npmjs.com/#getting-started): `npm install react-native-immutable-list-view --save`
37+
- Using [Yarn](https://yarnpkg.com/): `yarn add react-native-immutable-list-view`
2738

28-
## Usage
39+
2. Import it in your JS:
2940

30-
```js
31-
import ImmutableListView from 'react-native-immutable-list-view';
32-
```
41+
```js
42+
import ImmutableListView from 'react-native-immutable-list-view';
43+
```
3344

34-
`ImmutableListView` supports all the props of React Native's [ListView](https://facebook.github.io/react-native/docs/listview.html),
35-
but instead of passing in a `dataSource`, you should should pass in a prop called `immutableData`
36-
consisting of the data you'd like to display. `ImmutableListView` will handle creating an efficient `dataSource` for you.
45+
It supports all the props of React Native's [`ListView`](https://facebook.github.io/react-native/docs/listview.html#props),
46+
but instead of passing in a `dataSource`, you should should pass in a prop called `immutableData`.
47+
48+
This prop is just the raw data you'd like to display -- `ImmutableListView` will handle creating an efficient `dataSource` for you.
3749
Other than this small change, everything else will be exactly the same as `ListView`.
3850

3951
There's an example app [here](https://github.com/cooperka/react-native-immutable-list-view/tree/master/example)
40-
if you'd like to see it in action; have a look at the example diff below if you want to implement it yourself.
52+
if you'd like to see it in action.
4153

4254
## Example Usage
4355

44-
You can remove all that boilerplate in your constructor, as well as methods like
56+
You can remove all that boilerplate in your constructor, as well as lifecycle methods like
4557
`componentWillReceiveProps` if all they're doing is updating your `dataSource`.
46-
`ImmutableListView` will handle this for you. Check out this example diff:
58+
`ImmutableListView` will handle all of this for you.
59+
60+
Check out this example diff:
4761

48-
> Note: it looks much better on [GitHub](https://github.com/cooperka/react-native-immutable-list-view#example-usage) than on npm's site.
62+
> Note: This looks much better on [GitHub](https://github.com/cooperka/react-native-immutable-list-view#example-usage) than on npm's site.
63+
> Red means delete, green means add.
4964

5065
```diff
5166
-import { Text, View, ListView } from 'react-native';
@@ -108,16 +123,16 @@ You can remove all that boilerplate in your constructor, as well as methods like
108123

109124
## Props
110125

111-
All the props that React Native's [`ListView`](https://facebook.github.io/react-native/docs/listview.html)
112-
supports are passed through, and should work exactly the same.
126+
All the props supported by React Native's [`ListView`](https://facebook.github.io/react-native/docs/listview.html#props)
127+
are simply passed through, and should work exactly the same.
128+
129+
Simple, right?
113130
114131
| Prop name | Data type | Default value? | Description |
115132
|-----------|-----------|----------------|-------------|
116-
| `immutableData` | [`Immutable.Iterable`](https://facebook.github.io/immutable-js/docs/#/Iterable/isIterable) | Required. | The data to render. |
117-
| `rowsDuringInteraction` | `number` | `undefined` | How many rows of data to initially display while waiting for interactions to finish (e.g. Navigation animations). If unspecified, this will not have any effect. |
118-
| `sectionHeaderHasChanged` | `func` | `(prevSectionData, nextSectionData) => false` | Return true if your section header is dependent on your row data (uncommon). See [ListViewDataSource#constructor](https://facebook.github.io/react-native/docs/listviewdatasource.html#constructor) for more info. |
119-
120-
Simple, right?
133+
| `immutableData` | Any [`Immutable.Iterable`](https://facebook.github.io/immutable-js/docs/#/Iterable/isIterable) | Required. | The data to render. See below for some examples. |
134+
| `rowsDuringInteraction` | `number` | `undefined` | How many rows of data to initially display while waiting for interactions to finish (e.g. Navigation animations). |
135+
| `sectionHeaderHasChanged` | `func` | `(prevSectionData, nextSectionData) => false` | Return true if your section header is dependent on your row data (uncommon; see [`ListViewDataSource`'s constructor](https://facebook.github.io/react-native/docs/listviewdatasource.html#constructor) for more info). |
121136

122137
## How to format your data
123138

@@ -127,16 +142,16 @@ for list data. Here are some examples:
127142
#### List
128143

129144
```js
130-
[ <rowData1>, <rowData2>, ... ]
145+
[rowData1, rowData2, ...]
131146
```
132147

133148
#### Map of Lists
134149

135150
```js
136151
{
137152
section1: [
138-
<rowData1>,
139-
<rowData2>,
153+
rowData1,
154+
rowData2,
140155
...
141156
],
142157
...
@@ -148,8 +163,8 @@ for list data. Here are some examples:
148163
```js
149164
{
150165
section1: {
151-
rowID_1: <rowData1>,
152-
rowID_2: <rowData2>,
166+
rowId1: rowData1,
167+
rowId2: rowData2,
153168
...
154169
},
155170
...
@@ -163,19 +178,11 @@ To try it out yourself, you can use the [example app](https://github.com/cooperk
163178
When using section headers, `ImmutableListView` treats certain types of `Immutable.Map` slightly differently
164179
than `ListView` treats an equivalent plain JS `Map`. See the snapshot test output
165180
[here](https://github.com/cooperka/react-native-immutable-list-view/blob/master/src/__tests__/__snapshots__/ImmutableListView.test.js.snap)
166-
for an example of how `ImmutableListView` behaves.
181+
for an example of how `ImmutableListView` behaves, or try it for yourself.
167182

168183
It seems based on the [current documentation](https://facebook.github.io/react-native/releases/0.37/docs/listviewdatasource.html#constructor)
169184
that **`ImmutableListView` is behaving as expected**, and in fact regular `ListView` is the one being weird.
170185
In any case, you should make sure to test this behavior yourself if you're using a `Map` with section headers.
171186
172187
Other than this, the two should behave identically. You can verify this with the unit tests
173188
[here](https://github.com/cooperka/react-native-immutable-list-view/blob/master/src/__tests__/comparison.test.js).
174-
175-
## Contributing
176-
177-
1. Fork it!
178-
2. Create your feature branch: `git checkout -b my-new-feature`
179-
3. Commit your changes: `git commit -am 'Add some feature'`
180-
4. Push to the branch: `git push origin my-new-feature`
181-
5. Submit a pull request :D

0 commit comments

Comments
 (0)