Giter VIP home page Giter VIP logo

ng-channel's Introduction

archived Archived Repository
This code is no longer maintained. Feel free to fork it, but use it at your own risks.

ngChannel

Brings channels to AngularJS.

Installation

It is available with bower:

bower install ng-channel

Then add the retrieved files to your HTML layout:

<script type="text/javascript" src="/path/to/bower_components/ng-channel/ng-channel.min.js"></script>

You can also use it with RequireJS as an AMD module.

Then add ngChannel as dependency for your AngularJS application:

var app = angular.module('YOUR_APP', ['ngChannel']);

Configuration

Out of the box, ngChannel uses $$asyncCallback from angular to call asynchronously the channels' subscribers. You can provide an another by calling $channelFactory.asyncCallbackFactory(YOUR_FACTORY).

Usage

ngChannel exposes a service $channelFactory to build channels:

var channel = $channelFactory();

You can now pipe as many subscribers as you wish to your channel:

channel.pipe(function(message) {
   // message is the one broadcasted in the channel
});

// if you wish you can use dependency injection
channel.pipe(['myService', function(myService) {
    return function(message) {
        // This is a subscriber but you can now deal with myService
    };
}]);

To send a message in the channel, call send method:

channel.send('Yeah Ho!');

You can also pipe a channel with others channels:

var otherChannel = $channelFactory();
channel.pipe(otherChannel);

otherChannel.pipe(function(message) {
   // this subcriber will also be triggered by any message send in `channel`
});

Furthermore you can pipe the output of a subscriber:

channel.pipe(function(message) {
    return 'Ho!'
}).pipe(function(message) {
    // message is now `Ho!`
});

// If you wish you can also pipe it to another channel

channel.pipe(function(message) {
    return 'Ho!'
}).pipe(anotherChannel);

If you just want to add several subscribers at once on the same channel, you can use pipeChain:

channel
    .pipeChain(function(message) {
        // it will receive message from channel
    })
    .pipeChain(function(message) {
        // it will receive message from channel and not from the previous subscriber
    });

Build

To rebuild the minified JavaScript you must run: make build.

Tests

Install dependencies and run the unit tests:

make install
make test-spec

Contributing

All contributions are welcome and must pass the tests. If you add a new feature, please write tests for it.

License

This application is available under the MIT License, courtesy of marmelab.

ng-channel's People

Contributors

alexisjanvier avatar robinbressan avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.