Skip to content

Instantly share code, notes, and snippets.

@gmarty
Created March 22, 2016 18:53
Show Gist options
  • Save gmarty/871c4f629207c7214ef2 to your computer and use it in GitHub Desktop.
Save gmarty/871c4f629207c7214ef2 to your computer and use it in GitHub Desktop.
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