Created
June 9, 2013 13:18
-
-
Save anasnakawa/5743495 to your computer and use it in GitHub Desktop.
knockout js component class
This file contains 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
// 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