Skip to content

Commit

Permalink
FLUID-4162: Support for out-of-order construction of autoInit creator…
Browse files Browse the repository at this point in the history
… function and namespace with the same name
  • Loading branch information
amb26 committed Mar 29, 2011
1 parent 91fff12 commit 1b8c5e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/webapp/framework/core/js/Fluid.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,14 @@ var fluid = fluid || fluid_1_4;
if (!options.initFunction) {
fluid.fail("Cannot autoInit component " + componentName + " which does not have an initFunction defined");
}
fluid.setGlobalValue(componentName, function () {
var creator = function() {
return fluid.initComponent(componentName, arguments);
});
};
var existing = fluid.getGlobalValue(componentName);
if (existing) {
$.extend(creator, existing);
}
fluid.setGlobalValue(componentName, creator);
};

fluid.defaults("fluid.littleComponent", {
Expand Down
13 changes: 8 additions & 5 deletions src/webapp/tests/framework-tests/core/js/FluidIoCTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,17 +830,20 @@ fluid.registerNamespace("fluid.tests");
that.initFunctionRecord = [];
};

fluid.tests.initRecordingComponent = function(that) {
// Test FLUID-4162 by creating namespace before component of the same name
fluid.registerNamespace("fluid.tests.initFunctions");

fluid.tests.initFunctions.initRecordingComponent = function(that) {
var parent = that.options.parent;
parent.initFunctionRecord.push(that.options.name);
};

fluid.defaults("fluid.tests.recordingComponent", {
fluid.defaults("fluid.tests.initFunctions.recordingComponent", {
gradeNames: ["fluid.littleComponent", "autoInit"],
mergePolicy: {
parent: "nomerge"
},
postInitFunction: fluid.tests.initRecordingComponent
postInitFunction: "fluid.tests.initFunctions.initRecordingComponent"
}
);

Expand All @@ -857,14 +860,14 @@ fluid.registerNamespace("fluid.tests");
},
components: {
initTimeComponent: {
type: "fluid.tests.recordingComponent",
type: "fluid.tests.initFunctions.recordingComponent",
options: {
parent: "{initFunctions}",
name: "initTimeComponent"
}
},
eventTimeComponent: {
type: "fluid.tests.recordingComponent",
type: "fluid.tests.initFunctions.recordingComponent",
createOnEvent: "mainEvent",
options: {
parent: "{initFunctions}",
Expand Down

0 comments on commit 1b8c5e0

Please sign in to comment.