Last active
August 25, 2016 00:06
-
-
Save ibare/b3a2939ebc1d771e2d7fea8d41f5eaf9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 WoowaView(options) { | |
return function() { | |
this.template = options.template; | |
this.render = function(list) { | |
var item = []; | |
for(var i=0; i<list.length; i++) { | |
item.push('<li>'+list[i]+'</li>') | |
} | |
document.body.innerHTML = this.template.replace('{{list}}', item.join('')); | |
} | |
} | |
} | |
var View = WoowaView({ | |
template: '<ol>{{list}}</ol>' | |
}); | |
var view = new View1(); | |
This file contains hidden or 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 WoowaView(options) { | |
var View = function(model) { | |
this.container = options.container; | |
this.template = options.template; | |
this.viewWillMount = options.viewWillMount; | |
this.model = model || []; | |
this.render(); | |
}; | |
View.prototype.render = function() { | |
if (this.viewWillMount) { | |
this._render(this.viewWillMount(this.model)); | |
} else { | |
this._render(this.model); | |
} | |
}; | |
View.prototype._render = function(list) { | |
var item = []; | |
for(var i=0; i<list.length; i++) { | |
item.push('<li>'+list[i]+'</li>') | |
} | |
$(this.container).html(this.template.replace('{{list}}', item.join(''))); | |
}; | |
return View; | |
} | |
var View = WoowaView({ | |
container: '.contents', | |
template: '<ol>{{list}}</ol>', | |
viewWillMount: function(model) { | |
for (var i=0; i<model.length; i++) { | |
if (model[i] % 2 == 0) { | |
model[i] = model[i] * 10; | |
} | |
} | |
return model; | |
} | |
}); | |
var view = new View([1,2,3,4,5,7]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment