Skip to content

Added a simpler interface to weave that does not need target function iteration#1

Open
ichernev wants to merge 1 commit intogtanner:masterfrom
ichernev:master
Open

Added a simpler interface to weave that does not need target function iteration#1
ichernev wants to merge 1 commit intogtanner:masterfrom
ichernev:master

Conversation

@ichernev
Copy link

@ichernev ichernev commented Apr 7, 2012

If you are wrapping big objects with many functions, traversing all of them each time you wrap may be costly. So I added a function fastAspect, which exports a similar interface, but the function names are not preloaded in before/after/around etc, but instead, you pass the function name as a string.

I agree that this is not the cleanest implementation, but I'm open to suggestions (as far as the solution does not iterate through the object's functions).

@gtanner
Copy link
Owner

gtanner commented Apr 9, 2012

This is a very interesting problem.

I want to do some timing tests to see what the overhead is for the iteration and see if it is a huge impact before we spend to much time refactoring.

I had an idea of a two phase aspect method to solve this issue.

  • Step 1: build up weave method and return aspect function that takes an instance of the type.
  • Step 2: call aspect function with a copy of that object.

That way for aspecting a collection of the same objects it saves the constuction of the weave object for each one.

@ichernev
Copy link
Author

ichernev commented Apr 9, 2012

Do you mean using prototypes? Like

weave = buildWeave(/* ... */);
weave.prototype = obj1;
wrapped1 = new weave();

weave.prototype = obj2;
wrapped2 = new weave();

Otherwise I don't think there is much sense in constructing the weave object beforehand, because the connection part will take as much time as constructing the weave (asymptotically).

@gkorland
Copy link

Something is missing from all the AOP/Mixin framework is a more general way to define the point cut.
i.e. according to regular expression.

e.g.

    weave.after('get*', function () {
        ...
    })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants