Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lawrencec/aspectos
Simple AOP library
https://github.com/lawrencec/aspectos
Last synced: 12 days ago
JSON representation
Simple AOP library
- Host: GitHub
- URL: https://github.com/lawrencec/aspectos
- Owner: lawrencec
- Created: 2012-02-19T14:16:56.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-08-18T11:02:17.000Z (over 12 years ago)
- Last Synced: 2024-11-13T01:37:45.894Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 160 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Aspectos [![Build Status](https://secure.travis-ci.org/lawrencec/aspectos.png)](http://travis-ci.org/lawrencec/aspectos)
A simple library to provide basic AOP (Aspect Oriented Programming) functionality to your scripts. It allows one to decorate
methods and functions with behaviours that are run either before, after or around (before and after) the decorated
method or function.## Cloning
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
git submodule update --init --recursive## Usage
Aspectos provides three methods to provide the basic aspects to your objects:
before()
,after()
,around()
. These allow
you to run other function before, after or around any method respectively.### before
var testObject = {
write: function() {
testValue += ' 2';
}
};
testObject.write = aspectos.before(testObject, 'write', function() {
testValue += '1';
});
testObject.write();
// should write out '1 2'## after
var testObject = {
write: function() {
testValue += '1';
}
};
testObject.write = aspectos.after(testObject, 'write', function() {
testValue += ' 2';
});
testObject.write();
// should write out '1 2'## around
var testObject = {
write: function() {
testValue += ' ';
}
};
testObject.write = aspectos.around(
testObject,
'write',
[
function() {
testValue += '1';
},
function() {
testValue += '2';
}
]
);
testObject.write();
//should write '1 2'## Tests
See the index.html file in the tests directory
If you have testem installed run it from the root directory of the repo.
testem
or
testem ci -b Chrome
Mocha tests can be run with phantomjs (note the ci hash parameter):
phantomjs ./lib/test-helpers/run-mocha.js file://localhost/$(pwd)/aspectos/src/tests/index.html#ci