Skip to content

Instantly share code, notes, and snippets.

@osbornm
Created September 4, 2015 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osbornm/0b2bae8aacb6e3e497ac to your computer and use it in GitHub Desktop.
Save osbornm/0b2bae8aacb6e3e497ac to your computer and use it in GitHub Desktop.
uppercut.js Announcement
<!-- Console Binding: Prints to console.log very helpful for debuging -->
<div>
<!-- ko console: someValue --> <!-- /ko -->
</div>
<!-- Any and Empty Bindings: works like if binding but with less to type -->
<div data-bind="any: items"> You have Items</div>
<div data-bind="empty: items"> You have No Items</div>
<!-- href Binding: uses the attr binding under the covers but is less to type -->
<a data-bind="href: url">click here</a>
// asObservable or asObservableArray: if passed an observable use that instance otherwise wrap it in a new observable
var myModel = function(options){
var self = this;
self.observable = ko.asObservable(options.possibleObservable);
self.observableArray = ko.asObservableArray(options.possibleObservableArray);
return self;
}
// Trackable Observables: the ability to revert to a "good" value
var myForm = function(){
var self = this;
self.value = ko.trackableObservable("initial value");
self.array = ko.trackableObservableArray([]);
self.saveForm = function() {
// some ajax call or something
self.value.commit();
self.array.commit();
}
self.cancelForm = function() {
self.value.reset();
self.array.reset();
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment