#Overview
Channels wraps Events, Commands and ReqRes as a single package. It's main use is to pass around when you'd like to share your events bus with multiple iFrames or have a single triggering engine. Such cases arise mainly when you'd like to trigger events between iFrames / Apps.
Channels exists in the /dist/ folder and the /dist/min/ folder as Channels.js.
Example :
var channel = new Chronos.Channels(options);
Options can contain:
Parameter | Type | Description | Defaults |
---|---|---|---|
config | Object | Configuration for protocols | None |
events | Events Instance | A Chronos.Events instance | None |
commands | Commands Instance | A Chronos.Commands instance | None |
reqres | ReqRes Instance | A Chronos.ReqRes instance | None |
externalProxy | Boolean | Allows Courier to automatically trigger events to all iFrames that share Channels | false |
In order to share your events across iFrames you must set the "externalProxy" flag to true.
config object options:
Parameter | Type | Description | Defaults |
---|---|---|---|
events | Object | A Chronos.Events configuration object | None |
commands | Object | A Chronos.Commands configuration object | None |
reqres | Object | A Chronos.ReqRes configuration object | None |
Sample Code:
var channel = new Chronos.Channels({
externalProxy : true,
config: {
events: {},
commands: {},
reqres: {},
}
});
Exposed Instance API:
-
once //From Events
-
hasFiredEvents //From Events
-
trigger //From Events
-
publish //From Events
-
bind //From Events
-
register //From Events
-
unbind //From Events
-
unregister //From Events
-
hasFiredCommands //From Commands
-
comply //From Commands
-
stopComplying //From Commands
-
command //From Commands
-
hasFiredReqres //From ReqRes
-
request //From ReqRes
-
reply //From ReqRes
-
stopReplying //From ReqRes
-
registerProxy
##registerProxy If the externalProxy flag was set to true in the options, then this method is added.
It allows triggering events to your proxy and automatically triggers Events to any PostMessageCourier instances using the same Channels instance.
This means your iFrames can get your Events for free.
Parameter | Type | Description | Defaults |
---|---|---|---|
trigger | Function | The proxy function to call when an event triggers | None |
context | Function Context | The execution context of the function | undefined |
Example:
var channel = new Chronos.Channels({
externalProxy : true
});
channel.registerProxy({
trigger: function(){
//DO something with arguments
},
context: myContext
});