Last active
May 24, 2016 05:21
-
-
Save henriquegogo/87a8a64f674158df31484d27c85ab368 to your computer and use it in GitHub Desktop.
Simplest view model with a third-part template engine
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 ViewModel(target_selector) { | |
var ctx = this; | |
var target = document.querySelector(target_selector); | |
var template = target.innerHTML; | |
this.render = function() { | |
target.innerHTML = render(template, ctx); // render() should be the third-part template engine | |
}; | |
} | |
function BodyViewModel() { | |
ViewModel.call(this, "body"); | |
this.title = "Hello World"; | |
this.user = { name: "Henrique", age: 31 }; | |
this.items = ['Daiane', 'Henrique', 'Letícia', 'Pedro Lucas']; | |
this.render(); | |
} | |
self.bodyViewModel = new BodyViewModel(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment