Skip to content

Commit

Permalink
added composite events
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jul 12, 2014
1 parent 8aa148d commit 2841522
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/body/Composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var Composite = {};

/**
* Generic add function. Adds one or many body(s), constraint(s) or a composite(s) to the given composite.
* Triggers `beforeAdd` and `afterAdd` events on the `composite`.
* @method add
* @param {composite} composite
* @param {} object
Expand All @@ -71,6 +72,8 @@ var Composite = {};
Composite.add = function(composite, object) {
var objects = [].concat(object);

Events.trigger(composite, 'beforeAdd', { object: object });

for (var i = 0; i < objects.length; i++) {
var obj = objects[i];

Expand All @@ -92,12 +95,15 @@ var Composite = {};
}
}

Events.trigger(composite, 'afterAdd', { object: object });

return composite;
};

/**
* Generic remove function. Removes one or many body(s), constraint(s) or a composite(s) to the given composite.
* Optionally searching its children recursively.
* Triggers `beforeRemove` and `afterRemove` events on the `composite`.
* @method remove
* @param {composite} composite
* @param {} object
Expand All @@ -107,6 +113,8 @@ var Composite = {};
Composite.remove = function(composite, object, deep) {
var objects = [].concat(object);

Events.trigger(composite, 'beforeRemove', { object: object });

for (var i = 0; i < objects.length; i++) {
var obj = objects[i];

Expand All @@ -128,6 +136,8 @@ var Composite = {};
}
}

Events.trigger(composite, 'afterRemove', { object: object });

return composite;
};

Expand Down Expand Up @@ -431,6 +441,52 @@ var Composite = {};
return composite;
};

/*
*
* Events Documentation
*
*/

/**
* Fired when a call to `Composite.add` is made, before objects have been added.
*
* @event beforeAdd
* @param {} event An event object
* @param {} event.object The object(s) to be added (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/

/**
* Fired when a call to `Composite.add` is made, after objects have been added.
*
* @event afterAdd
* @param {} event An event object
* @param {} event.object The object(s) that have been added (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/

/**
* Fired when a call to `Composite.remove` is made, before objects have been removed.
*
* @event beforeRemove
* @param {} event An event object
* @param {} event.object The object(s) to be removed (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/

/**
* Fired when a call to `Composite.remove` is made, after objects have been removed.
*
* @event afterRemove
* @param {} event An event object
* @param {} event.object The object(s) that have been removed (may be a single body, constraint, composite or a mixed array of these)
* @param {} event.source The source object of the event
* @param {} event.name The name of the event
*/

/*
*
* Properties Documentation
Expand Down

0 comments on commit 2841522

Please sign in to comment.