Skip to content

Commit a69602b

Browse files
author
GauravDS
committed
readme updated
1 parent 84dad6d commit a69602b

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# JSModel
1+
# react-native-jsmodel: JSModel
2+
![version](https://img.shields.io/badge/version-0.0.1-green.svg)
23

34
### Preface
45
Are you coming from iOS native development background, newbies to JavaScript & react-native.
@@ -11,7 +12,60 @@ This approach is quite same as them or even more better. No need to add more dyn
1112
- keyMapper to rename the field names.
1213
- ease to implement and use.
1314

15+
### Installation
16+
- Run this command `$ npm install react-native-jsmodel --save`
17+
1418
### Implementation
19+
- import in js file as `import JSModel from 'react-native-jsmodel';` [see example](https://github.com/dayitv89/react-native-jsmodel/blob/master/RNTestJSModel/MockModel.js)
20+
21+
```JavaScript
22+
import JSModel from 'react-native-jsmodel';
23+
24+
export default class MockModel extends JSModel {
25+
message() {
26+
return 'This message added by JSModel: ' + this.error.message;
27+
}
28+
}
29+
```
30+
31+
- Make object of your model as `const model = new MockModel(Mock);` [see example](https://github.com/dayitv89/react-native-jsmodel/blob/master/RNTestJSModel/index.ios.js#L14)
32+
33+
```JavaScript
34+
import React from 'react';
35+
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
36+
import MockModel from './MockModel';
37+
import Mock from './Mock.json';
38+
39+
export default class TestJSModel extends React.Component {
40+
render() {
41+
const model = new MockModel(Mock);
42+
return (
43+
<View style={styles.container}>
44+
<Text style={styles.welcome}>
45+
{model.message()}
46+
</Text>
47+
</View>
48+
);
49+
}
50+
}
51+
const styles = StyleSheet.create({
52+
container: {
53+
flex: 1,
54+
justifyContent: 'center',
55+
alignItems: 'center',
56+
backgroundColor: '#F5FCFF'
57+
},
58+
welcome: {
59+
fontSize: 20,
60+
textAlign: 'center',
61+
margin: 10
62+
}
63+
});
64+
65+
AppRegistry.registerComponent('TestJSModel', () => TestJSModel);
66+
```
67+
68+
##### In detail:
1569
- Must inherit root object from `JSModel`. e.g. `class Parent extends JSONModel`.
1670
- Just inherit all models from `JSModel` that need to implement some methods, otherwise no need to create class. e.g. `common` & `root` is implemented but `orignal` is not implemented.
1771
- In parent model add child object as below.
@@ -53,7 +107,17 @@ console.log(JSON.stringify(modelObj, null, 2));
53107

54108
To test this demo code run: `$ npm i && npm start`
55109

110+
### Checklist
111+
- [x] Basic model
112+
- [x] Object Cloning
113+
- [x] keyMapper
114+
- [ ] Array parsing using static method as `JSModel.parseArray(ClassName, jsonArray)`
115+
- [ ] accessor & mutator concept for props.
116+
- [ ] Advance Model with type check using `prop-types`
117+
- [ ] Test cases for model (jest/mocha/ ** or something better**)
118+
- [ ] travis-ci setup
119+
56120
### Feedbacks
57-
- I love to hear your valuable feedbacks, suggestions & issues. Please raise a issue on the repo or email me @ `[email protected]`.
121+
- I love to hear your valuable feedbacks, suggestions & issues. Please raise a issue on the repo or email me (as subject: 'jsmodel#issue &lt;topic&gt;') @ `[email protected]`.
58122

59123
❤️ Voila! Happy coding...

0 commit comments

Comments
 (0)