+v15
Plugins are targeted for dynamic parts which can be removed when aren't used. Plugins are the best way for dynamic pages, forms, windows, etc. in SPA / Single Page Applications.
Topics:
exports
?Good to know:
<script>
is removedIMPORTANT:events
orwatchers
declared in the plugin scope will be removed automatically if the plugin is removed
name
can contain a-z
chars only (no numbers or white characters)PLUGIN('name_of_plugin', function(exports) {
// You can define your custom functions or properties
exports.myfunction_1 = function() {
console.log('something');
};
exports.myfunction_2 = function() {
console.log('something');
};
exports.myfunction_N = function() {
console.log('something');
};
// 2 way data-binding watcher:
WATCH('some.path', function(path, value) {
// ...
});
// Events
ON('some.event', fucntion(req) {
// ...
});
});
PLUGIN('name_of_plugin', function(exports) {
// A parent element of the <script> element
// {jQuery}
exports.element;
// A plugin name
// {String}
exports.name;
});
PLUGIN('name_of_plugin', function(exports) {
exports.something = function() {
// Method: scope()
// Enables a private scope for global methods like GET(), SET(), etc..
// +v17
exports.scope();
console.log(GET('?.name'));
// Will be evaluated as GET('name_of_plugin.name');
SET('?.age', 30);
// Will be evaluated as SET('name_of_plugin.age', 30);
// Good to know:
// Another "plugin.scope()" can rewrite current scope.
};
});
Plugins support only the one delegate destroy
. This delegate is executed when the plugin will be destroyed.
PLUGIN('name_of_plugin', function(exports) {
exports.destroy = function() {
// is executed when the plugin is destroyed
};
});
exports
?This is very easy, you can use EXEC
method:
EXEC('name_of_plugin/myfunction_1', arg1, arg2, argN);
You can get instance of the plugin very easy, just call PLUGIN(name)
without second argument, for example:
var exports = PLUGIN('name_of_plugin');
if (exports)
exports.myfunction_1();
.html
files