registry.js 474 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var reduce = require('object.reduce');
  3. var validateRegistry = require('./helpers/validateRegistry');
  4. function setTasks(inst, task, name) {
  5. inst.set(name, task);
  6. return inst;
  7. }
  8. function registry(newRegistry) {
  9. if (!newRegistry) {
  10. return this._registry;
  11. }
  12. validateRegistry(newRegistry);
  13. var tasks = this._registry.tasks();
  14. this._registry = reduce(tasks, setTasks, newRegistry);
  15. this._registry.init(this);
  16. }
  17. module.exports = registry;