Skip to content

Goctionni/CommandEvents

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

CommandEvents

JS file to allow cross extension function calls

This script allows you to send commands to other extensions also using it. Access to functions is granted based on a whitelist. You can whitelist a function by adding its path to eventCmd.whitelist. For example, lets say you have a function Model.getContacts();, to expose this function you would add 'Model.getContacts' to eventCmd.whitelist.

Lets say that an extension called UserTagger has a function like: Model.getUsertag('Username');. If they have added this function to their whitelist, you can call the function as follows:

eventCmd.send('UserTagger', ['Model', 'getUsertag'], ['Username'], function(usertag){
    console.log("Received usertag:" usertag);
});

The arguments for eventCmd.send() are as follows:
TargetExtension, Path(Array), Arguments(Array), Success(Callback), Error(Callback).

Functions that are called can either return their value immediately or return a Promise object.

If your function is passed a callback as an argument, you can call this function as follows:

var successCallback = function(){
    // Successful!
    console.log(arguments);
}
var errorCallback = function(){
    // Something went wrong!
    console.error(arguments);
}

eventCmd.send('ExtName', ['Async', 'get'], [eventCmd.eventCmd.successCallback, eventCmd.errorCallback], successCallback, errorCallback);

About

JS file to allow cross extension function calls

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published