View on GitHub

axn

listenable actions

Download this project as a .zip file Download this project as a tar.gz file

Synopsis

axn is a small (< 1.1 kB minified, ~440 bytes gzipped) implementation of listenable actions or signals in JavaScript.

license - MIT Dependencies

NPM status

browser support

Build Status Coverage Status

Install

Node.js

With NPM

npm install axn

From source

git clone https://github.com/pluma/axn.git
cd axn
npm install
npm run test && npm run dist

Browser

With component

component install pluma/axn

Learn more about component.

With bower

bower install axn

Learn more about bower.

With a CommonJS module loader

Download the latest minified CommonJS release and add it to your project.

Learn more about CommonJS modules.

With an AMD module loader

Download the latest minified AMD release and add it to your project.

Learn more about AMD modules.

As a standalone library

Download the latest minified standalone release and add it to your project.

<script src="/your/js/path/axn.globals.min.js"></script>

This makes the axn module available in the global namespace.

API

axn([spec]):Function

Creates a new action.

If spec is an object, its properties will be copied to the new action, overwriting its default properties.

action(data)

Invokes the action's listeners with the given data.

action.listen(fn, [ctx]):Function

Adds a given function to the action's listeners. If ctx is provided, the function will be invoked using it as its this context.

Returns a function that will remove the listener from the action.

action.unlisten(fn, [ctx]):Boolean

Removes the given function with the given context from the action's listeners.

Returns true if the listener was removed successfully, otherwise returns false.

action.beforeEmit(data):data

Override this function in your action's spec to pre-process data passed to the action before it is emitted.

The return value will be passed to the action's listeners.

action.shouldEmit(data):Boolean

Override this function in your action's spec to define whether data should be emitted.

This function is passed the output of beforeEmit. If the function returns false or a non-truthy value, the data will not be emitted. Otherwise the action's listeners will be invoked as normally.

axn.methods

An object containing the default properties that will be copied to new actions.

License

The MIT/Expat license. For more information, see http://pluma.mit-license.org/ or the accompanying LICENSE file.