Skip to content
This repository has been archived by the owner on Jan 30, 2022. It is now read-only.

Commit

Permalink
gallery-2010.05.05-19-39 ericf gallery-base-componentmgr
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed May 5, 2010
1 parent 610ca4b commit 6edaaa7
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/gallery-base-componentmgr/js/base-componentmgr.js
Expand Up @@ -54,27 +54,27 @@
// *** Public Methods *** //

/**
* Retrieves component instance(s) by component name or reference,
* any non-initialized components will be initalized.
* Component instance(s) will be passed to the callback as arguments.
* Supplies the callback with component instance(s) that were requested by string name or reference,
* any non-initialized components will be initialized.
* Component instance(s) will be passed to the callback as arguments in the order requested.
*
* @method getComponent
* @param component* {string|object} 1-n components to get/create instances of and return
* @method useComponent
* @param component* {string|object} 1-n components to use and/or create instances of
* @param *callback {function} callback to pass component instances to
*/
getComponent : function () {
useComponent : function () {

Y.log('getComponent called', 'info', 'baseComponentMgr');
Y.log('useComponent called', 'info', 'baseComponentMgr');

var args = Y.Array(arguments, 0, true),
components = args.slice(0, -1),
callback = isFunction(args[args.length-1]) ? args[args.length-1] : noop,
callback = isFunction(args[args.length-1]) ? args[args.length-1] : noop, // last param or noop
components = callback === noop ? args : args.slice(0, -1), // if callback is noop then all params, otherwise all but last params
instances = [],
initialized;

if (components.length < 1) {
Y.log('getComponent: no components, returning', 'info', 'baseComponentMgr');
callback.call(this, null);
callback.call(this);
return;
}

Expand All @@ -100,6 +100,20 @@
}
},

/**
* Retrieves component an instance by string name or reference.
* The components must have previously been initialized otherwise null is returned.
*
* @method getComponent
* @param component {string|object} component to get instance of
* @return component instance {object} the component instance if previously initialized, otherwise null
*/
getComponent : function (component) {

Y.log('getComponent called', 'info', 'baseComponentMgr');
return this._getInstance(component);
},

// *** Private Methods *** //

_getComponent : function (c) {
Expand Down Expand Up @@ -144,7 +158,7 @@
if ( ! c.instance) {
var initFn = isFunction(c.initializer) ? c.initializer :
isString(c.initializer) && isFunction(this[c.initializer]) ? this[c.initializer] : noop;
try { c.instance = initFn.call(this); } catch(e){}
c.instance = initFn.call(this);
}

return c.instance || null;
Expand Down

0 comments on commit 6edaaa7

Please sign in to comment.