forked from cujojs/wire
-
Notifications
You must be signed in to change notification settings - Fork 3
wire aop
Brian Cavalier edited this page Sep 1, 2011
·
5 revisions
This plugin lets you apply AOP techniques like decorators, introductions (mixins), and pointcut-based advice aspects to components during the wiring process.
{
module: 'wire/debug',
// aspects
// Array of aspects to apply during wiring
aspects: [
// Can reference aspects declared later in the wire spec
'refToAspect1',
'refToAspect2',
// Or pointcuts can be declared explicitly
{
// pointcut can be Array of Strings, RegExp, or String ref
// name of pointcut declared later in the wire spec
pointcut: ['aMethodNameToAdvise', 'anotherMethodNameToAdvise'],
// Reference to advice declared later in the wire spec
advice: 'refToAdvice'
}
// ... more aspects ...
]
}
Decorators allow you to apply a standard decorator pattern explicitly to components in the wire spec.
{
// Add the wire/aop plugin
plugins: [
{ module: 'wire/aop' }
],
// Create a decorator
// This should be a function that will decorate a component
myDecorator: { module: 'my/Decorator' },
// Create a component
myComponent: {
// Create an instance of my/Component
create: 'my/Component',
// Explicitly decorate it with myDecorator
// myComponent will be passed as the first parameter to
// myDecorator. Other args specified below will be the
// second, third, etc. parameters.
decorate: {
myDecorator: [/* other args to pass to decorator function */]
}
}
}
More coming soon
Introductions allow you to mixin functionality to components in the wire spec.
{
// Add the wire/aop plugin
plugins: [
{ module: 'wire/aop' }
],
// Create the mixin
// This can be any object
myMixin: { module: 'my/Mixin' },
// Create a component
myComponent: {
// Create an instance of my/Component
create: 'my/Component',
// Explicitly introduce myMixin into myComponent.
// All of myMixins properties will be added to myComponent.
introduce: ['myMixin' /*, ... other mixins ... */]
// Shorthand if you only have a single mixin:
// introduce: 'myMixin'
}
}
More coming soon
More coming soon
More coming soon