Created
March 22, 2016 18:53
-
-
Save gmarty/871c4f629207c7214ef2 to your computer and use it in GitHub Desktop.
This file contains 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 BaseService from 'base-service'; | |
import fetchJSON from 'fetch-json'; | |
const _private = { | |
// Immutable properties. | |
manufacturer: Symbol('manufacturer'), | |
model: Symbol('model'), | |
// Mutable states. | |
state: Symbol('state') | |
}; | |
export default class Service extends BaseService { | |
constructor(props, state) { | |
super(props); | |
// Immutable properties. | |
this[_private.manufacturer] = props.manufacturer; | |
this[_private.model] = props.model; | |
// Mutable states. | |
this[_private.state] = { | |
on: state.on | |
}; | |
} | |
get manufacturer() { | |
return this[_private.manufacturer]; | |
} | |
get model() { | |
return this[_private.model]; | |
} | |
turnOn(value = false) { | |
fetchJSON(`/service/${this.id}/state`, { on: value }) | |
.then(() => { | |
this[_private.state].on = value; | |
return value; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment