Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model mapper support #83

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
lib/
coverage/
node_modules/
flow-typed/
.eslintcache
*.log
*.swp
*.rpt2*
.idea
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ REST conventions for mobx.
- [Model](#model)
- [Collection](#collection)
- [apiClient](#apiclient)
- [modelMapper](#modelMapper)
- [Simple Example](#simple-example)
- [State shape](#state-shape)
- [FAQ](#faq)
Expand Down Expand Up @@ -604,6 +605,29 @@ All options:
* **headers**: Additional request headers, like `Authorization`
* **tbd.**

### `modelMapper`
You may need to use different kind of models while sending request and using in mobx-rest
There are currently one implementation:

- One using `Basic` and `Auto` mappers in the [mobx-rest-auto-mapper-adapter](https://github.com/emrahtoy/mobx-rest-auto-mapper-adapter) package.

For example, if you're using an api takes and returns different kind of models or you are using view model different than api model, you use username for view and name for api request, it could look like this:

```
import modelMapper from "mobx-rest";
import { BasicModelMapper } from "./mobx-rest-auto-mapper-adapter";

modelMapper(new BasicModelMapper());

const modelMap=[['username','name']];

class User extends Model {} // I assume you create proper model here.

let user = new User({username:"Emrah TOY"},{username:"Emrah TOY"},modelMap);
user.save() // will send {name:"Emrah TOY"} to given api endpoint. username -> name
```
Please, visit model mappers githup repo for much more complicated examples.

## Simple Example

A collection looks like this:
Expand Down
Loading