0.0.3 • Published 10 years ago
attachable v0.0.3
attachable
Simple object to bidirectionally track its attachments (links,connections) to other attachable objects
You can
obj1.attachTo(obj2)And later
console.log( obj2.isAttachedTo(obj1) );
// trueIf you have different needs regarding the functionality, please add a feature request.
Installation
npm install --save attachableUsage
// var attachable=require('attachable');
var attachable=require('./index.js');
var obj1={}; attachable(obj1);
var obj2={}; attachable(obj2);
obj1.attachTo(obj2);
obj2.isAttachedTo(obj1);
// true
obj1.isAttachedTo(obj2);
// true
obj2.detachFrom(obj1)
obj2.isAttachedTo(obj1);
// false
obj1.isAttachedTo(obj2);
// falseMethods
attachTo(attachable)Attach to specific attachable object (and also attach that object to this one)
detachFrom(attachable)Detach from specific attachable object (and also attach that object from this one)
detachAll() Detach object from all currently attached attachable objects
boolean hasAttached()Allows to check if this object has other attachable objects attached to it (it is attached to some other attachable objects)
boolean isAttachedTo(attachable)Allows to check if the object attached to another attachable object
Credits
Links to package pages:
github.com npmjs.com travis-ci.org coveralls.io inch-ci.org
License
MIT