soma.js update 1.0.1 plugin system

| 1 min read

I've added a plugin system in soma.js and a tutorial how to create a plugin on the site.

It is quite simple and everything is explained in the tutorial step by step, but here is a quick overview.

To create a plugin, you just need to create a function that will receive a soma framework instance and any additional parameter.

var MyPlugin = function(instance, myParam) {
this.instance = instance;
this.myParam = myParam;
}

Another syntax that might be helpful, especially if you want to extend the plugin later on.

var MyPlugin = soma.extend({
constructor: function(instance, myParam) {
this.instance = instance;
this.myParam = myParam;
}
});

Now that you have access to the framework instance, you can create models, wires, commands, events, and so on.

To use the plugin, you just need to instantiate it in either a framework instance, a wire or a command.

var SomaApplication = soma.Application.extend({
init: function() {
var plugin = this.createPlugin(MyPlugin, "my param");
}
});
var app = new SomaApplication();

That's it!

Check out a more advanced plugin with the step by step tutorial on the soma.js site.