From 0dc4b133fb0795b9c55f8a9fc95b55bc4df7ebf2 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Thu, 11 Apr 2013 16:42:11 +0200 Subject: Builder: return object when it's already built https://fedorahosted.org/freeipa/ticket/3235 --- install/ui/src/freeipa/_base/Builder.js | 1 + install/ui/src/freeipa/_base/construct.js | 20 ++++++++++++++++++-- install/ui/src/freeipa/ipa.js | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'install/ui/src') diff --git a/install/ui/src/freeipa/_base/Builder.js b/install/ui/src/freeipa/_base/Builder.js index 0eb76c4a..d01f86f1 100644 --- a/install/ui/src/freeipa/_base/Builder.js +++ b/install/ui/src/freeipa/_base/Builder.js @@ -84,6 +84,7 @@ define(['dojo/_base/declare', var f,c; if (spec === undefined || spec === null) return null; + if (!construct.is_spec(spec)) return spec; context = context || {}; diff --git a/install/ui/src/freeipa/_base/construct.js b/install/ui/src/freeipa/_base/construct.js index bc017ad6..e44c66b1 100644 --- a/install/ui/src/freeipa/_base/construct.js +++ b/install/ui/src/freeipa/_base/construct.js @@ -34,11 +34,27 @@ define(['dojo/_base/declare', */ is_ctor: function(obj) { - // TODO: Find better method. Check by extend might not be very - // reliable. return typeof obj === 'function' && typeof obj.extend === 'function'; }, + /** + * Finds out if object is a spec object. + * + * Object is not a spec object when any of following applies: + * * has __fw_obj === true + * * has isInstanceOf function - basically tells if it's a instance of + * dojo-based class + * + */ + is_spec: function(obj) { + var ret = false; + if (typeof obj === 'object') { + ret = obj.__fw_obj === true || + typeof obj.isInstanceOf === 'function'; + } + return !ret; + }, + /** * Creates copy of construction specification * diff --git a/install/ui/src/freeipa/ipa.js b/install/ui/src/freeipa/ipa.js index e252a782..c8bf4dae 100644 --- a/install/ui/src/freeipa/ipa.js +++ b/install/ui/src/freeipa/ipa.js @@ -293,9 +293,26 @@ var IPA = function() { } }; + that.obj_cls = function() {}; + that.obj_cls.prototype.__fw_obj = true; + return that; }(); +/** + * Basic object + * + * Framework objects created by factories should use this instead of {} when + * creating base objects. As an alternative they can just set __fw_obj + * property. + * + * __fw_obj property serves for telling the framework that it's instantiated + * object and not an object specification (spec). + */ +IPA.object = function() { + return new IPA.obj_cls(); +}; + IPA.get_credentials = function() { var status; -- cgit