Last active
September 29, 2017 23:35
-
-
Save PaquitoSoft/c011e18a2925e03e2f8a9ab0382a920a 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
class BasePage { | |
constructor(data = {}) { | |
this.state = data; | |
// Create the main HTMLElement for this page so we can | |
// attach DOMEvent listeners to it | |
this.$el = document.createElement('div'); | |
Object.keys(this.events || {}).forEach(key => { | |
const [eventName, selector] = key.split('|'); | |
this.$el.addEventListener(eventName, (function(selector, event) { | |
if (event.target.matches(selector)) { | |
this.events[key].call(this, event); | |
} | |
}).bind(this, selector)); | |
}); | |
} | |
updateState(newState) { | |
this.state = Object.assign({}, this.state, newState); | |
this.render(); | |
} | |
render() { | |
this.$el.innerHTML = this.html(); | |
return this.$el; | |
} | |
} | |
export default BasePage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment