Let’s say you have
Batman.AssociationSet, or even a plain JS array) whose members are
Batman.Model instances. You have a
saveAll function that saves all the members:
1 2 3
But what if you wanted to call a
callback when the whole operation was finished?
- Set up a listener on the
onceto avoid observer bloat.
- Before each save operation,
- When each one finishes,
That way, it will get prevented n times – once for each item in the set – and it will finally be fired when the last operation is finished.
Here it is, all together:
1 2 3 4 5 6 7 8 9 10 11 12
@allowAndFire are provided by
Batman.EventEmitter, so it will only work with objects which have that mixin. Don’t worry – every object in batman.js is an event emitter! But plain JS objects are not.