0.7.1 • Published 8 years ago

connexionjs v0.7.1

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

ConnexionJS

Emit and listen for events across different frames and execution contexts. Automatically synchronizes event history if any context is attached or created during runtime.

Installation

In a Browser environment include the instance of the ConnexionJS in every frame that should work with events:

<script src="path/to/connexionjs/dist/connexion.min.js"></script>

Then in the source code use global variable in the context of a frame

connexion.listen('event', function(){})
connexion.emit('event')

In a CommonJS environment first install it from NPM:

$ npm install connexionjs

then in the source code use

	var connexion = require('connexionjs')
	connexion.listen('event', function(){})
	connexion.emit('event')

Usage

Include a library in any window. Start listening and emitting events.

In a main frame

connexion.emit('main-event')
connexion.listen('main-event' , function(eventDetail){
	console.log(eventDetail) //undefined
})
connexion.listen('frame-event' , function(eventDetail){
	console.log(eventDetail) //{a: 1, b: 2}
})

In any child frame

connexion.emit('frame-event', {a: 1, b: 2})
connexion.listen('main-event' , function(eventDetail){
	console.log(eventDetail) //undefined
})
connexion.listen('frame-event' , function(eventDetail){
	console.log(eventDetail) //{a: 1, b: 2}
})

API reference:

connexion.emit(eventType: String, [eventDetail: Object])

Emits event with an object attached to it. An event detail is optional.

connexion.listen(eventType: String, handler: Function)

Listens events that are emitted.

connexion.observe(eventType: String, handler: Function)

Observes events that are emitted. Like connexion.listen() but additionally calls handler in a moment of attachment with the latest data of event. Suitable for handling of events from the past.

connexion.unsubscribe(eventType: String, [handler: Function])

Removes event handler for a given event type. If handler is not provided then all handlers of a given event type are removed.

connexion.version: String

The version of the library. Sinse the version is important for compatibility between different instancies of ConnexionJS this property can be checked programmatically to see if they match. Versions are compatible if "patch" versions match (e.g. 1.1.x)

Use cases

  • Communiation between iframes and main window on any direction even across different origins;
  • Communication between different tabs/windows of the same origin;
  • Communication between different script contexts in browser extensions: background scripts, content scripts, popup scripts;
  • Communication between Node and Webkit context on the Node-Webkit platform;
  • Mediator object in a Browser web application;
  • Mediator object in a NodeJS application.

Compatibility

Browsersupport
self
frames
tabs
workers
Node-webkit <=0.11support
self
frames
windows-
NodeJS
NWJS >=0.13support
self
frames
windows
NodeJS-
Browser extensionsupport
self
background
content
popup
NodeJS >=0.10support
self
child processes-
parallel processes-

Polyfills that may be required for old platforms:

  • Array indexOf() (IE <=8)
  • Function bind() (IE <=8, FF <=3.6, SF <=5.0.5, CH <6, OP <=11.50)
  • Object.keys() (IE <=8, FF <=3.6, SF <=4.0.5, OP <=11.50)
0.7.1

8 years ago

0.7.0

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.2

8 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.5

9 years ago