New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

angular-channel

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-channel

This is very much a proof of concept/work in progress and could do with improvements.

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

Angular Channels

This is very much a proof of concept/work in progress and could do with improvements.

Example Usage

Create an event channel service

angular.module('myApp.security', ['mouki.channel'])
  .service('SecurityChannel', function($rootScope, EventChannel) {

    var serviceChannel = new EventChannel("SecurityChannel");
    
    // Return an object that has the method logout and onLogout
    return serviceChannel.build(['logout']);
  });

Create a custom event channel service

angular.module('myApp.security', ['mouki.channel'])
  .service('SecurityChannel', function($rootScope, EventChannel) {

    var serviceChannel = new EventChannel("SecurityChannel");
    var _LOGOUT_EVENT_ = 'logout';

    return {
      logout: function (data) {
        serviceChannel.emit(_LOGOUT_EVENT_, data);
      },
      onLogout: function ($scope, handler) {
        return serviceChannel.register($scope, _LOGOUT_EVENT_, handler);
      }
    }
  });

angular.module('myApp.security').service('SecurityService', function(SecurityChannel) {
    return {
      logout: function() {
        // Do actual logout call
        // Notify
        SecurityChannel.logout();
      }
    };
  });

Using the channel


angular.module('myApp.view1', ['ngRoute', 'myApp.security'])

.controller('View1Ctrl', function($scope, $log, SecurityChannel, SecurityService) {

    $scope.logout = function() {
      SecurityService.logout();
    };

    var onLogoutCleanup = SecurityChannel.onLogout($scope, function(item){
      $log.info("Logged out!");
    });

    $scope.$on('$destroy', function() {
      $log.debug("Removing handler");
      onLogoutCleanup();
    });
});

Thanks :)

Based on the work of Eric Burley and Jim Lavin.

Initial Gruntfile.js borrowed from ngStorage :)

FAQs

Package last updated on 02 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts