Skip to content
/ meld Public
forked from cujojs/meld

AOP for JS with before, around, on, afterReturning, afterThrowing, after advice, and pointcuts

License

Notifications You must be signed in to change notification settings

vivane/meld

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Aspect Oriented Programming for Javascript. It allows you to change the behavior of, or add behavior to methods and functions (including constructors) non-invasively.

As a simple example, instead of changing code, you can use meld to log the result of myObject.doSomething:

var myObject = {
	doSomething: function(a, b) {
		return a + b;
	}
};

// Call a function after myObject.doSomething returns
var remover = meld.after(myObject, 'doSomething', function(result) {
	console.log('myObject.doSomething returned: ' + result);
});

myObject.doSomething(1, 2); // Logs: "myObject.doSomething returned: 3"

remover.remove();

myObject.doSomething(1, 2); // Nothing logged

Docs

API docs

Quick Start

AMD

  1. git clone https://github.com/cujojs/meld or git submodule add https://github.com/cujojs/meld

  2. Configure your loader with a package:

    packages: [
    	{ name: 'meld', location: 'path/to/meld', main: 'meld' },
    	// ... other packages ...
    ]
  3. define(['meld', ...], function(meld, ...) { ... }); or require(['meld', ...], function(meld, ...) { ... });

Script Tag

  1. git clone https://github.com/cujojs/meld or git submodule add https://github.com/cujojs/meld
  2. <script src="https://redirect.github.com/path/to/meld/meld.js"></script>
  3. meld will be available as window.meld

Node

  1. npm install meld
  2. var meld = require('meld');

RingoJS

  1. ringo-admin install cujojs/meld
  2. var meld = require('meld');

Running the Unit Tests

Install buster.js

npm install -g buster

Run unit tests in Node:

  1. buster test -e node

Run unit tests in Browsers (and Node):

  1. buster server - this will print a url
  2. Point browsers at /capture, e.g. localhost:1111/capture
  3. buster test or buster test -e browser

Changelog

0.7.2

  • Fix for context when advising constructors: this is now the constructed instance in all advice functions.

0.7.1

  • Fix for global name when using meld as a browser global. Thanks @scothis
  • Update unit tests to run in browser using buster server, in addition to node. Thanks again, @scothis :)

0.7.0

  • Advice can be applied directly to functions without a context.
  • Advice can be applied to constructors.
  • joinpoint.proceed() can be called multiple times. This makes it possible to implement "retry" types of advice.

0.6.0

0.5.4

  • Optimizations to run time advice invocation, especially around advice
  • Fix for passing new args to joinpoint.proceed() in around advice
  • Added joinpoint.proceedApply(array) for proceeding and supplying new arguments as an array
  • Ported unit tests to BusterJS

0.5.3

  • First official release as part of cujojs
  • Minor doc and package.json tweaks

0.5.2

  • Revert to larger, more builder-friendly module boilerplate. No functional change.

0.5.1

  • Minor corrections and updates to package.json

0.5.0

  • Rewritten Advisor that allows entire aspects to be unwoven (removed) easily.

Beers to:

About

AOP for JS with before, around, on, afterReturning, afterThrowing, after advice, and pointcuts

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%