preposterous

Adds ability to automatically fire before (pre) and after (post) events when a method is called

PrePosterous

Small library that fires 'before' (pre) and 'after' (post) events when methods are called.

The Jasmine testing framework is used for the tests and is added as a submodule.

You can either clone this repo with the submodules in one command like so:

git clone REPO_URL --recursive

or separately

git clone REPO_URL
<cd clonedrepo>
git submodule update --init --recursive

Ender and the following dependencies are required.

aspectos bean

A pre-built ender.js (with all dependencies) is provided in the /lib directory. If you have ender installed you can re-build ender.js and the dependencies by ender refresh in the /lib directory.

Aspectos provides three methods to provide the basic functionality of firing events before, after or around any specified method.

var ActionObject = {
        doAction : preposterous.pre(
            function(args) {

            },
            'action' //event name to fire
        )
    },
    handlerObject = {
        handler: function(e) {

        }
    };


// listen
subscribe(ActionObject, 'beforeAction', handlerObject);
// fire
ActionObject.doAction();
// handlerObj.handler will get called receiving an event of 'beforeAction'
var ActionObject = {
        doAction : preposterous.post(
            function(args) {

            },
            'action' //event name to fire
        )
    },
    handlerObject = {
        handler: function(e) {

        }
    }


// listen
subscribe(ActionObject, 'action', handlerObject);
// fire
ActionObject.doAction();
// handlerObj.handler will get called receiving an event of 'action'
var ActionObject = {
        doAction : preposterous.prepost(
            function(args) {

            },
            'action' //event name to fire
        )
    },
    handlerObject = {
        handler: function(e) {

        }
    },
    spiedCallback = spyOn(handlerObject, 'handler').andCallThrough();

// listen
subscribe(ActionObject, 'beforeAction', spiedCallback);
subscribe(ActionObject, 'action', spiedCallback);
// fire
ActionObject.doAction();
// handlerObj.handler will get called twice first receiving an event of 'beforeAction'
// and then again receiving an event of 'action'.

See the index.html file in the tests directory