Skip to content

Instantly share code, notes, and snippets.

@ihollander
Last active November 27, 2018 18:17
Show Gist options
  • Save ihollander/ec36e5c162d572c71583cb3b0d2c037e to your computer and use it in GitHub Desktop.
Save ihollander/ec36e5c162d572c71583cb3b0d2c037e to your computer and use it in GitHub Desktop.
Observer Pattern pt3
class FluxController extends EventEmitter {
constructor(model, view) {
super()
this.model = model
this.view = view
// add event listeners for changes to our model state
model.addEventListener('daytime', () => this.changeViewToDaytime())
model.addEventListener('nighttime', () => this.changeViewToNighttime())
// set the initial state
model.isNighttime ? this.changeViewToNighttime() : this.changeViewToDaytime()
}
changeViewToDaytime() {
this.view.body.style.color = '#000'
this.view.body.style.backgroundColor = '#fff'
}
changeViewToNighttime() {
this.view.body.style.color = '#fff'
this.view.body.style.backgroundColor = '#000'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment