Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Last active May 24, 2016 05:21
Show Gist options
  • Save henriquegogo/87a8a64f674158df31484d27c85ab368 to your computer and use it in GitHub Desktop.
Save henriquegogo/87a8a64f674158df31484d27c85ab368 to your computer and use it in GitHub Desktop.
Simplest view model with a third-part template engine
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