Skip to content

Instantly share code, notes, and snippets.

@anasnakawa
Created June 9, 2013 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anasnakawa/5743495 to your computer and use it in GitHub Desktop.
Save anasnakawa/5743495 to your computer and use it in GitHub Desktop.
knockout js component class
// ui component class structure
// ----------------------------
(function(sandbox) {
'use strict';
var Component = function(foo, bar) {
this.foo = foo;
this.bar = bar;
// define your component lifecycle here
this.init();
return this;
}
Component.prototype = {
constructor: Component
, init: function() {
}
// Component class methods
, ComponentItem: function() {
}
}
// component kos custom bindings
// -----------------------------
Component.bindingHandlers = {
componentDoSomething: {
init: function(element, value, bindings, viewModel, context) {
}
, update: function(element, value, bindings, viewModel, context) {
}
}
}
// expose your component
// ---------------------
sandbox.Component = Component;
// expose your custom bindings
// ---------------------------
ko.bindingHandlers.componentDoSomething = Component.bindingHandlers.componentDoSomething;
})(sandbox);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment