Created
March 20, 2015 20:32
-
-
Save anonymous/200ecd9aebf28f392d93 to your computer and use it in GitHub Desktop.
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
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