@stamp/collision
Controls collision behavior: forbid or defer
This stamp (aka behavior) will check if there are any conflicts on every compose call. Throws an Error in case of a forbidden collision or ambiguous setup.
Usage
import Collision from '@stamp/collision';
const ForbidRedrawCollision = Collision.collisionSetup({forbid: ['redraw']});Or if you don't want to import the stamp you can import only the method:
import {collisionSetup} from '@stamp/collision';
const ForbidRedrawCollision = collisionSetup({forbid: ['redraw']});The defer collects same named methods and wraps them into a single method.
import Collision from '@stamp/collision';
import {Border, Button, Graph} from './drawable/primitives';
const UiComponent = Collision.collisionSetup({defer: ['draw']})
.compose(Border, Button, Graph);
const component = UiComponent();
const results = component.draw(); // will draw() all three primitives
console.log(results.length); // prints "3" to the console.The deferred method returns the array of the values your methods returned. In the example above the results array will have the values the .draw() methods returned.
API
Static methods
collisionSetup
Forbid or Defer an exclusive method stamp.collisionSetup({forbid: ['methodName1'], defer: ['methodName2']}) -> Stamp
collisionProtectAnyMethod
Forbid any collisions, excluding those allowed stamp.collisionProtectAnyMethod({allow: ['methoName']}) -> Stamp
collisionSettingsReset
Remove any Collision settings from the stamp stamp.collisionSettingsReset() -> Stamp
Example
See the comments in the code:
Last updated