aisle

Module for global event handling and namespacing.

Usage no npm install needed!

<script type="module">
  import aisle from 'https://cdn.skypack.dev/aisle';
</script>

README

aisle

Build Status Dependency Status

Module for global event handling and namespacing.

$ npm install aisle

Usage

Programmatically

var aisle = require("aisle");

Call your aisle for namespaces or use it as you would an EventEmitter object.

Namespaces

If you call aisle without any arguments, then aisle will tap into and return require.main.exports, otherwise aisle will return your namespace and its data. If you provide data with your namespace, then aisle will assign that data to your namespace (namespaces will be created or overwritten.)

// main.js
var aisle = require("aisle");

module.exports = {"data": "main"};

aisle("my-namespace",{"abc": 123});

require("./other");
// other.js
var aisle = require("aisle");

console.log(aisle()); // { data: 'main' }
console.log(aisle("my-namespace")); // { abc: 123 }
console.log(aisle("nonexistent-namespace")); // undefined

Events

With your Node's version, use Node's documentation to find its EventEmitter abilities.

// main.js
var aisle = require("aisle");

aisle.on("some global event",console.log); // { data: [ 'here', true ] }

require("./other");
// other.js
var aisle = require("aisle");

aisle.emit("some global event",{"data": ["here",true]});