Last active
March 24, 2016 19:32
-
-
Save bshack/839c00ed7ecc65847c15 to your computer and use it in GitHub Desktop.
simple js view for being extended
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
(function() { | |
'use strict'; | |
const View = require('./viewBase.js'); | |
new View({ | |
el: document.querySelector('a'), | |
model: {'foo': 'bar'} | |
}); | |
})(); |
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
(function() { | |
'use strict'; | |
const _ = require('underscore'); | |
module.exports = function(options) { | |
//cache this | |
let self = this; | |
//initialize | |
self.init = function() { | |
self.addListeners(); | |
window.console.log('init', self); | |
}; | |
self.el = document.createElement('div'); | |
//empty model | |
self.model = { | |
}; | |
//set up events | |
self.addListeners = function() { | |
self.el.addEventListener('click', self.eventClick); | |
}; | |
//click event | |
self.eventClick = function(e) { | |
window.console.log(e, self); | |
e.preventDefault(); | |
}; | |
//render the view | |
self.render = function() {}; | |
//extendable view | |
self = _.extend(self, options); | |
// init on instantiation | |
self.init(); | |
// now run render on instantiation | |
self.render(); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to make a fork (couldn't edit). You can follow the link at the top or just go here: https://gist.github.com/gibbitz/8e3d0ad18370f6e1f578