Ale.js

Plugin

Using plugins

We need to load a plugin using the Ale.use function:

1
Ale.use();

The Ale.use function takes a parameter to specify the Ale plugin object to load. For example, we pass in an Ale plugin object named test:

1
Ale.use(test);

test is actually a variable. In the following sections, we will learn how to make an Ale plugin object.

Making plugins

First let’s define an object:

1
2
3
4
/* Define a variable called test */
var test = {

}

If you want test to be an Ale plugin object, then it must have at least the name and install attributes:

1
2
3
4
5
6
7
var test = {
name: "test", /* Plugin name */
install: function(){
/* Install function, which is called when the user uses the plugin */
alert("Hello!");
}
}

You can add functions or properties to the letotype property of the Ale object in the install property…

Anyway, the installer supports arbitrary JavaScript code!

Plugin object

Call any content inside the plugin via the Ale.plugin.function name format.

The functions currently built into the plugin object are as follows:

  • inject() [The inject function takes a parameter, the type needs to be function, which is used to inject content into the component (it will be triggered whenever the component is rendered)]
1
2
3
4
Ale.plugin.inject(function(obj){
/* Add a parameter, obj is the ale component object when the component is rendered */
console.log(obj);
})
  • mixin() [mixin is triggered when the component is defined, and the injection is triggered when the component is rendered (using the same way as injection)]
1
2
3
4
5
6
7
Ale.plugin.mixin(function(obj){
/* Add a parameter, obj is the configuration parameter added when the user defines the component, not the ale component object! ! ! ! */
console.log(obj);

/* Here you need to use return to return obj, otherwise the component will be registered as undefined! ! */
return obj;
})

Online instance

We have defined an Ale plugin object called test, now let’s install it by typing Ale.use(test) in the console! (Hello will be output during installation!)


Found some errors? Edit on Github!