mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Builder: return object when it's already built
https://fedorahosted.org/freeipa/ticket/3235
This commit is contained in:
@@ -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 || {};
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ test('Testing builder', function() {
|
||||
|
||||
var o2 = b2.build({});
|
||||
var o21 = b2.build({ foo: 'baz'});
|
||||
var o22 = b2.build(o21);
|
||||
|
||||
var r1 = { foo: 'bar' };
|
||||
var r11 = { foo: 'baz' };
|
||||
@@ -71,6 +72,8 @@ test('Testing builder', function() {
|
||||
deepEqual(o2, r2, 'Constructor, default');
|
||||
deepEqual(o21, r21, 'Constructor, spec use');
|
||||
|
||||
strictEqual(o21, o22, 'Don\'t build built object');
|
||||
|
||||
});
|
||||
|
||||
test('Testing Spec_mod', function() {
|
||||
|
||||
Reference in New Issue
Block a user