(docs) Models and contributing docs (#130)

* Models and contributing docs

* Fix links

* Update models.md

* Fix nested list
This commit is contained in:
Timothee Guerin 2017-01-26 16:10:28 -08:00 коммит произвёл GitHub
Родитель 66ab1f986a
Коммит 582b1f40e2
4 изменённых файлов: 90 добавлений и 0 удалений

12
CONTRIBUTING.md Normal file
Просмотреть файл

@ -0,0 +1,12 @@
# Contributing to BatchLabs
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
### Pull request message format
Use a good description for the title(i.e. not just `Merge feature/awesome-stuff in master`)
If applicable please use the `fix #[issue number]` in the pull request description
e.g.
```markdown
fix #123
```

Просмотреть файл

@ -22,6 +22,8 @@ npm run electron
```
## Developers
[Dev docs](docs/readme.md)
For developers, you can set up a development environment as follows:
Start the dev server

72
docs/models.md Normal file
Просмотреть файл

@ -0,0 +1,72 @@
# Writing a model
This is a documentation to help create models which are DataStructure that maps entities returned by apis.
All models should be immmutable using `immutable.Record` otherwise the `RxProxy` that is using immutable `List` and `Map` will not handle those correctly.
Immutable.js will convert those to a Map automatically which then lose the ability to run `myModel.myAttr`
If you are just making a model that is internal to a component:
* doesn't it really need to be shared with others
* if yes maybe just export from the component file/folder
### Step 1: Create file
Create model file `myNewModel.ts` in `app/models`
add this to `app/models/index.ts`
```typescript
export * from "./myNewModel"
```
Then you should be able to have
```typescript
// Good
import { MyNewModel } from "app/models"
// Bad
import {MyNewModel} from "app/models/myNewModel"
```
### Step 2: Write the Record
Use this to specify default values for each input. This is quite useful for inputs which are array for example and prevent a null check later in the code
**It is important to have every input defined here otherwise they will be ignored**
```typescript
import { List, Record } from "immutable";
const FooRecord = Record({
id: null,
state: null,
files: List([]),
bar: null,
});
```
### Step 3: Write the model class
You'll need to redefine the inputs. This is for typing purposes.
```typescript
export class Foo extends FooRecord {
public id: string;
public state: string;
public files: List<string>;
public bar: Bar;
}
```
### Step 4(If applicable): created nested Record
In the case some of the attributes are other models(Record). Then you'll need to do the following to make sure they are initialized correctly
```typescript
// Add this constructor
constructor(data: any = {}) {
super(Object.assign({}, data, {
files: List(data.files),
bar: data.bar && new Bar(data.bar),
}));
}
```

4
docs/readme.md Normal file
Просмотреть файл

@ -0,0 +1,4 @@
# Dev docs
* [Models](models.md)
* [Testing](testing.md)