Extend components and plugins with EXTENSION
EXTENSION(name, config, callback) adds code to every instance of the component name (or of the plugin @name) when it is created. The callback receives the instance and its config, exactly like a declaration, so you can add methods, change options or listen to events. It is how an application customizes third-party components without forking them.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jComponent</title>
<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
<ui-component name="label" config="text:Hello"></ui-component>
<script>
COMPONENT('label', 'text:', function(self, config) {
self.make = function() {
self.html('<span></span>');
self.find('span').text(config.text);
};
});
EXTENSION('label', 'suffix:!', function(self, config) {
self.shout = function() {
self.find('span').text(config.text.toUpperCase() + config.suffix);
};
self.extended = true;
});
</script>
</body>
</html> Try it in your browser
Edit the example and run it. It runs in an isolated frame in your browser; nothing is sent to our server.
Preview