Git Product home page Git Product logo

axn's Introduction

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.

axn's People

Contributors

natew avatar pluma avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.