npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-aop

v0.4.5

Published

Framework for aspect-oriented programming with AngularJS

Downloads

7

Readme

Travis CI Join the chat at https://gitter.im/mgechev/angular-aop

Online demo

If you prefer learning by doing (trial and error), come right this way.

API

AngularAOP allows you to apply aspect-oriented programming in your AngularJS applications.

If you notice that you have cross-cutting concerns you can isolate them in individual services and apply them as follows:

myModule.config(function ($provide, executeProvider) {
  executeProvider.annotate($provide, {
    ServiceToWove: [{
      jointPoint: JOINT_POINT,
      advice: ADVICE_NAME,
      methodPattern: /Special/
      argsPattern: [/arg1/, /arg2/]
    }, {
      jointPoint: JOINT_POINT
      advice: ADVICE_NAME
    }]
  });
});

The joint-points supported in the current version of the framework are:

  • after - the advice will be invoked after the target method
  • afterResolveOf - the advice will be invoked after the promise returned by target method has been resolved and after the resolve callback attached to the promise is invoked
  • aroundAsync - the advice will be invoked before the target method was invoked and after the promise returned by it was resolved
  • around - the advice will be invoked before the target method was invoked and after it was invoked
  • beforeAsync - the target method will be called after the promise returned by the advice was resolved
  • before - the target method will be invoked after the advice
  • onRejectOf - the advice will be invoked when the promise returned by the target method was rejected
  • onResolveOf - the advice will be invoked after the promise returned by the target method was resolved but before the resolve callback attached to the promise is invoked
  • onThrowOf - the advice will be called if the target method throws an error

For additional information about Aspect-Oriented Programming and AngularAOP visit the project's documentation and this blog post.

Change log

v0.1.0

New way of annotating. Now you can annotate in your config callback:

DemoApp.config(function ($provide, executeProvider) {
  executeProvider.annotate($provide, {
    ArticlesCollection: {
      jointPoint: 'before',
      advice: 'Logger',
      methodPattern: /Special/,
      argsPatterns: [/arg1/, /arg2/, ..., /argn/]
    }
  });
});

v0.1.1

Multiple aspects can be applied to single service through the new way of annotation:

DemoApp.config(function ($provide, executeProvider) {
  executeProvider.annotate($provide, {
    ArticlesCollection: [{
      jointPoint: 'before',
      advice: 'Logger',
    }, {
      //aspect 2
    }, {
      //aspect 3
    }, ... , {
      //aspect n
    }]
  });
});

Note: In this way you won't couple your target methods/objects with the aspect at all but your target service must be defined as provider.

v0.2.0

Added forceObject property to the rules. This way issues like #12 will not be reproducable since we can force the framework to wrap the target's method, insted of the target itself (in case the target is a function with "static" methods").

Issues fixed:

  • Once a function is wrapped into an aspect its methods are preserved. We add the target to be prototype of the wrapper, this way using the prototype chain the required methods could be found.

v0.2.1

Added tests for:

  • Before async joint-point
  • On resolve joint-point

Add JSCS and update Gruntfile.js

v0.3.1

  • deep config property, which allows adding wrappers to prototype methods
  • Fix forceObject

v0.3.1

  • Wrap the non-minified code in build in IIFE (Issue 15)
  • Single 'use strict'; at the top of the IIFE

v0.4.0

  • Add the joint-point names as constants to the executeProvider, so now the following code is valid:
myModule.config(function ($provide, executeProvider) {
  executeProvider.annotate($provide, {
    ServiceToWove: [{
      jointPoint: executeProvider.ON_THROW,
      advice: ADVICE_NAME,
      methodPattern: /Special/
      argsPattern: [/arg1/, /arg2/]
    }, {
      jointPoint: executeProvider.BEFORE,
      advice: ADVICE_NAME
    }]
  });
});
  • Add more tests

v0.4.1

  • Special polyfill for IE9 of Object.setPrototypeOf.

Roadmap

  1. joinpoint.proceed()
  2. Use proper execution context inside the target services. This will fix the issue of invoking non-woven internal methods.
  3. More flexible way of defining pointcuts (patching $provide.provider might be required)

Known issues

Circular dependency

This is not issue in AngularAOP but something which should be considered when using Dependency Injection.

Note that if the $injector tries to get a service that depends on itself, either directly or indirectly you will get error "Circular dependency". To fix this, construct your dependency chain such that there are no circular dependencies. Check the following article, it can give you a basic idea how to procceed.

Contributors

| | | | | | :---: |:---: |:---: |:---: |:---: |:---: | mgechev |david-gang |Wizek |slobo |christianacca |peernohell |

License

AngularAOP is distributed under the terms of the MIT license.