Skip to content

Latest commit

 

History

History
106 lines (73 loc) · 3.16 KB

Channels.md

File metadata and controls

106 lines (73 loc) · 3.16 KB

#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:

  1. once //From Events

  2. hasFiredEvents //From Events

  3. trigger //From Events

  4. publish //From Events

  5. bind //From Events

  6. register //From Events

  7. unbind //From Events

  8. unregister //From Events

  9. hasFiredCommands //From Commands

  10. comply //From Commands

  11. stopComplying //From Commands

  12. command //From Commands

  13. hasFiredReqres //From ReqRes

  14. request //From ReqRes

  15. reply //From ReqRes

  16. stopReplying //From ReqRes

  17. 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
    });