Last active
November 27, 2018 18:17
-
-
Save ihollander/ec36e5c162d572c71583cb3b0d2c037e to your computer and use it in GitHub Desktop.
Observer Pattern pt3
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
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