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

angularjs-state-emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angularjs-state-emitter

modify shared state through an message bus

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
6
-40%
Maintainers
1
Weekly downloads
 
Created
Source

angularjs-state-emitter

API stability NPM version Downloads Standard

Use an event-based api similar to choo's to manage shared state in your Angular.js 1.x app.

Usage

1. Register angularjs-state-emitter as a dependency of your app:

var stateEmitter = require('angularjs-state-emitter')

angular.module('myApp', [stateEmitter])

2. Declare your store in a run block:

angular.run(store)

function store (state, emitter) {
  state.clicks = 0

  emitter.on('increment', function () {
    state.clicks += 1
    emitter.emit('render')
  })
}

3. Pass state down from your root component:

function ComponentCtrl (state) {
  var ctrl = this
  ctrl.state = state
}
<my-component state="$ctrl.state"></my-component>

it also works with @ui-router/angularjs:

$stateProvider.state({
  name: 'layout',
  component: 'myComponent',
});
<ui-view state="$ctrl.state"></ui-view>

4. Emit actions from any components

module.exports = {
  template: `<button ng-click="$ctrl.handleClick()">increment</button>`,
  bindings: { 
    state: '<' 
  },
  controller: function ButtonCtrl (emit) {
    var ctrl = this

    ctrl.handleClick = function () {
      emit('increment')
    }
  }
}

Installation

npm install angularjs-state-emitter

Logging

Enable logging through the $stateEmitterProvider in a config block:

function myConfig ($stateEmitterProvider) {
  $stateEmitterProvider.debug(true)
}

See also

Keywords

angularjs

FAQs

Package last updated on 17 Aug 2018

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