Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2015 20:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anonymous/200ecd9aebf28f392d93 to your computer and use it in GitHub Desktop.
Save anonymous/200ecd9aebf28f392d93 to your computer and use it in GitHub Desktop.
var MyComponent = Factory({
willMount: function(element, context) {
console.log('component mounted', element.tagName);
};
willUnmount: function(element, context) {
console.log('component unmount', element.tagName);
};
view: function() {
return m('.component', 'hello');
}
});
// would be transformed to:
var MyComponent = {
controller: function() {
this.willMount = function(element, context) {
console.log('component mounted', element.tagName);
};
this.willUnmount = function(element, context) {
console.log('component unmount', element.tagName);
};
},
view: function(ctrl) {
return m('.component', {
config: function(element, isInitialised, context) {
if (!isInitialised && ctrl.willMount) ctrl.willMount(element, context);
if (ctrl.willUnmount) {
context.onunload = function() {
ctrl.willUnmount(element, context);
}
}
}
}, 'hello');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment