New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

twill

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twill - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

test/aspect-all-after.js

46

lib/twill.js

@@ -22,3 +22,3 @@ function _funcs(obj) {

func.apply(target, arguments);
orig.apply(target, arguments);
return orig.apply(target, arguments);
};

@@ -32,4 +32,5 @@ };

target[name] = function () {
orig.apply(target, arguments);
var result = orig.apply(target, arguments);
func.apply(target, arguments);
return result;
};

@@ -43,3 +44,3 @@ };

target[name] = function () {
func.apply(target, [arguments, orig]);
return func.apply(target, [arguments, orig]);
};

@@ -72,13 +73,28 @@ };

all: {
before: function () {
throw "not done :(";
before: function (method) {
var funcs = _funcs(target);
funcs.forEach(function (f) {
_pointcut(target).before(f)(function () {
method(f, arguments);
});
});
},
after: function () {
throw "not done :(";
after: function (method) {
var funcs = _funcs(target);
funcs.forEach(function (f) {
_pointcut(target).after(f)(function () {
method(f, arguments);
});
});
},
around: function () {
throw "not done :(";
},
create: function () {
throw "not done :(";
around: function (method) {
var funcs = _funcs(target);
funcs.forEach(function (f) {
_pointcut(target).around(f)(function (args, orig) {
return method(f, args, orig);
});
});
}

@@ -90,9 +106,3 @@ }

weave.before[f] = _pointcut(target).before(f);
});
functions.forEach(function (f) {
weave.after[f] = _pointcut(target).after(f);
});
functions.forEach(function (f) {
weave.around[f] = _pointcut(target).around(f);

@@ -99,0 +109,0 @@ });

{
"name": "twill",
"version": "0.0.1",
"version": "0.0.2",
"description": "a clean javascript aspect oriented microframework",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/gtanner/twill",

@@ -1,2 +0,2 @@

=twill
# twill
A new approch to javascript aspect oriented programming. Twill is an attempt to create

@@ -6,7 +6,7 @@ an AOP framework for javascript that feels like it was written for javascript. Twill

=install
# install
npm install twill
=example
# example

@@ -95,3 +95,3 @@ var twill = require("twill"),

=todo:
# todo:

@@ -102,4 +102,5 @@ This is a very early release and not everything is done just yet.

- unweaving is not supported yet.
- make it work in the browser
=how to develop
# how to develop

@@ -106,0 +107,0 @@ all code should have tests written in node-unit. Run the tests with:

@@ -60,3 +60,21 @@ var twill = require("../lib/twill");

target.merp();
},
"it still returns the value of the original method" : function (test) {
var target = {
doubleRainbow: function () {
return "OMG OMG OMG OMG OMG";
}
};
twill.aspect(target, function (weave) {
weave.after.doubleRainbow(function () {
return "meh";
});
});
test.equal("OMG OMG OMG OMG OMG", target.doubleRainbow());
test.done();
}
};

@@ -52,4 +52,21 @@ var twill = require("../lib/twill");

target.tangent();
},
"it returns the value from the aspect rather than the original" : function (test) {
var target = {
cow: function () {
return "says cluck";
}
};
twill.aspect(target, function (weave) {
weave.around.cow(function () {
return "says moo";
});
});
test.equals("says moo", target.cow());
test.done();
}
};
var twill = require("../lib/twill");
exports["when aspecting after a method"] = {
"it calls the aspect after the actual" : function (test) {
exports["when aspecting before a method"] = {
"it calls the aspect before the actual" : function (test) {
var msg = "",
target = {
f: function () {
msg += "hello";
msg += " world";
}

@@ -13,4 +13,4 @@ };

twill.aspect(target, function (weave) {
weave.after.f(function () {
msg += " world";
weave.before.f(function () {
msg += "hello";
});

@@ -61,3 +61,20 @@ });

target.merp();
},
"it still returns the return value from the original method" : function (test) {
var target = {
kungfu : function () {
return "i know it!";
}
};
twill.aspect(target, function (weave) {
weave.before.kungfu(function () {
return "the matrix has you";
});
});
test.equal("i know it!", target.kungfu());
test.done();
}
};

@@ -82,3 +82,2 @@ var twill = require("../lib/twill");

test.ok(typeof weave.all.around === 'function', "around should be a function");
test.ok(typeof weave.all.create === 'function', "create should be a function");
test.done();

@@ -121,1 +120,34 @@ });

};
exports["when aspecting"] = {
"it can declare and use multiple aspects" : function (test) {
var foo = {
bar: function () {},
baz: function () {},
fred: function () {}
},
result = "";
twill.aspect(foo, function (weave) {
weave.before.bar(function () {
result += "a";
});
weave.after.baz(function () {
result += "b";
});
weave.around.fred(function () {
result += "c";
});
});
foo.bar();
foo.baz();
foo.fred();
test.equal("abc", result);
test.done();
}
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc