Last active
May 22, 2018 13:25
-
-
Save scottdomes/8fe1bf15bedbbf1ed9abf0fe3c8097e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { toJS, observable } from 'mobx' | |
class Contact { | |
id = 0 | |
@observable name = '' | |
@observable number = '' | |
constructor(data) { | |
this.name = data.name | |
this.number = data.number | |
} | |
update() { | |
// Convert data from observable properties to normal JavaScript primitives | |
const contact = toJS(this) | |
// Then send it | |
fetch(API_URL + '/contacts/' + this.id, { | |
body: { contact }, | |
method: 'PATCH' | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment