Skip to content
Browse files

added factory fiber - useful for dynamically resolving components

  • Loading branch information...
1 parent 2dd7406 commit 141c4d0d249c7472fa452c8a5fa0e6e1b09ee53d @neonstalwart committed Jun 2, 2011
Showing with 57 additions and 0 deletions.
  1. +57 −0 lib/factory/Fiber.js
View
57 lib/factory/Fiber.js
@@ -0,0 +1,57 @@
+/**
+ * @license Copyright (c) 2011 Cello Software, LLC.
+ * All rights reserved.
+ * Available via the new BSD License.
+ */
+/*jshint
+ bitwise: false, curly: true, eqeqeq: true, forin: true, immed: true, indent: 4, maxlen: 100,
+ newcap: true, noarg: true, noempty: true, onevar: true, passfail: false, strict: true,
+ undef: true, white: true
+*/
+/*global define: false, require: false */
+
+define([
+ 'compose',
+ 'lang',
+ 'promise',
+ 'dojo/_base/array'
+], function (compose, lang, promise, array) {
+ 'use strict';
+ return compose(function FactoryFiber() {
+ this._listeners = [];
+ }, {
+ id: 'Factory Fiber',
+
+ init: function (kernel) {
+ this.kernel = kernel;
+ kernel.modelBuilder.addProcessor(this);
+ },
+
+ process: function (model, next) {
+ var kernel = this.kernel;
+ return promise.when(model, function (model) {
+ var factory = model.factory,
+ module = {};
+
+ if (factory) {
+ // model.factory is a map of
+ // propertyName -> moduleId
+ // instance.propertyName will be a factory for a moduleId
+ array.forEach(lang.keys(factory), function (property) {
+ module[property] = function (args) {
+ return kernel.resolve(factory[property], args);
+ };
+ });
+ model.module = module;
+ }
+ });
+ },
+
+ terminate: function () {
+ // stop all the listeners
+ array.forEach(this._listeners, function (listener) {
+ listener.remove();
+ });
+ }
+ });
+});

0 comments on commit 141c4d0

Please sign in to comment.
Something went wrong with that request. Please try again.