Message from JavaScript discussions
July 2017
— I am trying some Aspect Oriented Programming with Promises, but I am not sure how to automate the promise chain
An Aspect looks like this
Aspect.prototype.execute = function (state) {
return Promise.resolve(state)
.then(this.enter)
.catch(this.errorHandler)
.then(this.main)
.catch(this.errorHandler)
.then(this.exit)
.catch(this.errorHandler);
};
— And then I try chaining like this
function Strategy(...aspects) {
this.aspects = aspects;
}
Strategy.prototype.execute = function (...arguments) {
var curAspect = this.aspects[0].execute(arguments);
for (var loc = 1; loc < this.aspects.length; loc++) {
curAspect = curAspect.then(this.aspects[loc].execute);
}
};
— Since then
is a cw/cs function it is good for AOP I think
— But looking at that for
loop do you think that is a good way to chain?
— Uhm
—
promises.reduce((final, promise) =>
final.then(promise), Promise.resolve(state));
— Oh drerp I forgot about the high order array functions
— Heh
— Thank you haha
— This will allow two algorithms, diff
and clone
to be used to make diffClone
without changing them at all
— Ooooh