ac-registry
v1.0.0
Published
ac-registry ===========
Downloads
3
Readme
ac-registry
Install
npm install ac-registry --save
Usage Example
// A single/global registry is the default.
var registry = require('ac-registy');
// Adds a new type 'foo'
function FooType(props) { this.bar = props.bar; }
registry.setType('foo', FooType);
// Creates an instance of type 'foo'
var id = registry.add({type:'foo', bar: 'baz'});
// Gets the instance with id
var foo = registry.get(id);
foo.type; // -> 'foo'
foo.id === id; // -> true
foo.bar; // -> 'baz'
Relations between types
var registry = require('ac-registy');
function FooType(props) {
// Mixin the type 'bar'
registry.mixin.call(this, 'bar');
// Add all bars
props.bars.forEach(this.addBar.bind(this));
}
registry.setType('foo', FooType);
function BarType(props) { this.baz = props.baz; }
registry.setType('bar', BarType);
var id = registry.add({
type:'foo',
bars: [{
baz: 'buz'
}]
});
var foo = registry.get(id);
foo.eachBar(function(bar){
bar.type; // -> 'bar'
bar.baz; // -> 'buz'
});
See tests for more.
Run Tests
npm run test
MIT License
Copyright (c) 2016 Oliver Leics [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.