Skip to content

Instantly share code, notes, and snippets.

@scottdomes
Last active May 22, 2018 13:25
Show Gist options
  • Save scottdomes/8fe1bf15bedbbf1ed9abf0fe3c8097e9 to your computer and use it in GitHub Desktop.
Save scottdomes/8fe1bf15bedbbf1ed9abf0fe3c8097e9 to your computer and use it in GitHub Desktop.
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