Intro
You've seen before that when you collide (up) a simple function on something else, it's the function that's keeped as collision result :
deep.nodes({
myProp:true
})
.up({
myProp:function(){
return "hello world";
}
})
.log();
var a = {
myProp:function(){
return "hello world";
}
};
deep.aup({
myProp:function(){
return "hello overwrited world";
}
}, a);
deep.log(a.myProp());
In other words, the function overwrite the property value. (always the same rules : what's coming from 'up' (what is above) is at higher priority - an what is under is at lower priority)
Here comes AOP, compositions and promises.
Now, you want to manage more finely the result of functions collision.
The idea is simple : when two functions are collided, you choose which one is executed first and how wired them together.
So when two functions collide together (up or bottom), we could use deep.compose to manage how those functions are merged and wired.
deep.nodes({
myFunc:function(arg)
{
return "[" + arg + "]";
}
})
.up({
myFunc:deep.compose.after(function(arg){
return "{" + arg + "}";
})
})
.run("myFunc", "hello")
.log();
.after()
If the previous returns something, it will be injected as argument(s) in 'func'.
If the previous return nothing, th original arguments are injected in 'func'.
If the previous returns a promise or a chain : it will wait until the resolution of the returned value before executing 'func'.
If the previous returned object isn't a promise, 'func' is executed immediately.
Same thing for returned object(s) from 'func' : it will be chained..
var base = {
myFunc:function(arg)
{
return arg + " : myfunc base";
}
};
deep
.up({
myFunc:deep.compose.after(function(arg){
return arg + " : myfunc from after";
})
}, base);
deep.log(base.myFunc("hello"));
.before()
ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
deep.nodes(1).log();
.around()
ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
deep.nodes(1).log();
.fail()
ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
deep.nodes(1).log();
Create yours
ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
deep.nodes(1).log();