Code Block |
---|
|
/**
* Component creator function
*/
fluid.myComponent = function (container, options) {
var that = initView("fluid.myComponent", container, options);
that.model = {
...
};
that.field = that.locate("inputField");
// initDependents() will instantiate all three subcomponents
fluid.initDependents(that);
return that;
};
|
|
{code} | With {{[]}}{{}} {{}} {{}}. |
| {code:javascript}. | Code Block |
---|
|
/**
* Default options for the component
*/
fluid.defaults("fluid.myComponent", {
gradeNames: "fluid.viewComponent",
components: {
sub1: {
type: "fluid.subComponent1Impl"
},
sub2: {
type: "fluid.subComponent2Impl"
},
sub3: {
type: "fluid.subComponent3Impl"
}
},
selectors: {
inputField: ".flc-myComponent-inputField"
},
events: {
onSave: null,
afterSave: null
}
}); |
|
{code} | In the component | In the component defaults, |
__ {{}} {{}} \\
\\
The values for the {{type}} properties may be function names, but this is not necessary. The function to use for the types specified, as well as their arguments, are specified through {{[fluid.demands]}}{{()}}, shown below. |
| {tip:title=With IoC and "autoInit" grade} It is encouraged to use IoC system in conjunction with the component grade system. Using "autoInit" allows for simpler and more declarative implementation of component. The example of such "autoInit" component is below:{tip} |
| {code:javascript}
The values for the type properties may be function names, but this is not necessary. The function to use for the types specified, as well as their arguments, are specified through fluid.demands () , shown below.
| Tip |
---|
title | With IoC and "autoInit" grade |
---|
| It is encouraged to use IoC system in conjunction with the component grade system. Using "autoInit" allows for simpler and more declarative implementation of component. The example of such "autoInit" component is below: |
| Code Block |
---|
|
/**
* Default options for the component with autoInit grade.
*/
fluid.defaults("fluid.myComponent", {
gradeNames: ["fluid.viewComponent", "autoInit"],
preInitFunction: "fluid.myComponent.preInitFunction",
postInitFunction: "fluid.myComponent.postInitFunction",
components: {
sub1: {
type: "fluid.subComponent1Impl"
},
sub2: {
type: "fluid.subComponent2Impl"
},
sub3: {
type: "fluid.subComponent3Impl"
}
},
selectors: {
inputField: ".flc-myComponent-inputField"
},
events: {
onSave: null,
afterSave: null
}
});
fluid.myComponent.preInitFunction = function (that) {
that.model = {
...
};
};
fluid.myComponent.postInitFunction = function (that) {
that.field = that.locate("inputField");
};
|
|
{code} | With autoInit |
| {code:javascript} | Code Block |
---|
|
/**
* Subcomponent demands
*/
fluid.demands("fluid.subComponent1Impl", "myComponent", {
container: "{myComponent}.options.selectors.sub1container",
options: {
model: "{myComponent}.model",
field: "{myComponent}.field"
}
});
fluid.demands("fluid.subComponent2Impl", "myComponent", {
funcName: "fluid.mySubComponent2Impl",
args: ["{myComponent}.model"]
});
fluid.demands("fluid.subComponent3Impl", "myComponent", {
container: "{myComponent}.container",
options: {
events: {
onSave: "{myComponent}.onSave"
}
}
}); |
|
{code} | The calls to {{ | The calls to fluid.demands() |
}}
*
* function \\
\\
The second call to {{- function
The second call to fluid.demands()
|
}}
* {{fluid.mySubComponent2Impl
|
}} {{}} {{myComponent}}
* pass the {{model}} property of the parent component as a parameter |
| {code:javascript}-
myComponent - pass the
model property of the parent component as a parameter
| Code Block |
---|
|
/**
* Subcomponent demands
*/
fluid.demands("fluid.subComponent1Impl", ["testEnvironment", "myComponent"], {
funcName: "fluid.mySubComponent1Impl",
args: ["#test-markup", {
model: testData.model,
field: "{myComponent}.field",
}]
});
fluid.demands("fluid.subComponent2Impl", ["testEnvironment", "myComponent"], {
funcName: "fluid.mySubComponent2Impl",
args: [testData.model]
});
fluid.demands("fluid.subComponent3Impl", ["testEnvironment", "myComponent"], {
funcName: "fluid.myTest3Impl",
args: [$("#test-markup"), testOnSaveHandler]
}); |
|
{code} | Additional calls to {{ | Additional calls to fluid.demands() |
}} {{}} \\
\\
These additional demands specification can be made in a different file, if desired. For example, demands specific to a testing environment can be placed in the test files. |{span}
These additional demands specification can be made in a different file, if desired. For example, demands specific to a testing environment can be placed in the test files.
|
|