Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Note

This tutorial has not yet been updated to reflect post-1.4 Framework changes.

Div
classtutorial-linear-nav

Span
classtutorial-nav-left
Previous: Tutorial - View Components
Span
classtutorial-nav-centre
Up to overview
Span
classtutorial-nav-right
Next: Subcomponents

Div
classfloatRight
Panel
borderColor#ccc
bgColor#fff
titleOn This Page
borderStylesolid
Table of Contents
maxLevel5
minLevel2
maxLevel5
Div
classfloatRight
Panel
borderColor#ccc
bgColor#fff
titleSee Also
borderStylesolid

Renderer
Renderer Component Trees
Cutpoints

In the previous Tutorial - View Components currency converter example, you can notice two things:

...

A renderer component supports a model (just as model components and view components Tutorial - Model Components and Tutorial - View Components do). The model of a renderer component contains any data that is to be rendered by the component.

...

The mapping between the component tree and the template is specified using cutpoints Cutpoints: key/value pairs mapping the ID of the component in the tree to a selector for the element in the template. When you use the renderer component grade, the Framework automatically generates a list of cutpoints from the selectors specified in the component options.

...

Code Block
javascript
javascript

fluid.defaults("tutorials.currencyConverter", {
    gradeNames: ["fluid.rendererComponent", "autoInit"],
    selectors: {
        amount: ".tut-currencyConverter-amount",
        currency: ".tut-currencyConverter-currency-selecter",
        result: ".tut-currencyConverter-result"
    },
    model: {
        rates: {
            names: ["euro", "yen", "yuan", "usd", "rupee"],
            values: ["0.712", "81.841", "6.609", "1.02", "45.789"]
        },
        currentSelection: "0.712",
        amount: 0,
        result: 0
    },
    events: {
        conversionUpdated: null
    }
});

...

Code Block
javascript
javascript

tutorials.currencyConverter.produceTree = function (that) {
    return {
        amount: "${amount}",
        currency: {
            optionnames: "${rates.names}",
            optionlist: "${rates.values}",
            selection: "${currentSelection}"
        },
        result: "${result}"
    };
};

...

Code Block
javascript
javascript

fluid.defaults("tutorials.currencyConverter", {
    gradeNames: ["fluid.rendererComponent", "autoInit"],
    selectors: {
        amount: ".tut-currencyConverter-amount",
        currency: ".tut-currencyConverter-currency-selecter",
        result: ".tut-currencyConverter-result"
    },
    model: {
        rates: {
            names: ["euro", "yen", "yuan", "usd", "rupee"],
            values: ["0.712", "81.841", "6.609", "1.02", "45.789"]
        },
        currentSelection: "0.712",
        amount: 0,
        result: 0
    },
    events: {
        conversionUpdated: null
    },
    produceTree: "tutorials.currencyConverter.produceTree"
});

...

Code Block
javascript
javascript

var bindEventHanders = function (that) {
    // When the model changes, update the resulting "converted" value
    that.applier.modelChanged.addListener("amount", function () {
        that.convert(that.model.amount);
    });
    that.applier.modelChanged.addListener("currentSelection", function () {
        that.convert(that.model.amount);
    });
    that.applier.modelChanged.addListener("result", function () {
        that.refreshView();
    });
};

...

Code Block
javascript
javascript

fluid.defaults("tutorials.currencyConverter", {
    gradeNames: ["fluid.rendererComponent", "autoInit"],
    selectors: {
        amount: ".tut-currencyConverter-amount",
        currency: ".tut-currencyConverter-currency-selecter",
        result: ".tut-currencyConverter-result"
    },
    model: {
        rates: {
            names: ["euro", "yen", "yuan", "usd", "rupee"],
            values: ["0.712", "81.841", "6.609", "1.02", "45.789"]
        },
        currentSelection: "0.712",
        amount: 0,
        result: 0
    },
    events: {
        conversionUpdated: null
    },
    produceTree: "tutorials.currencyConverter.produceTree",
    finalInitFunction: "tutorials.currencyConverter.finalInit",
    renderOnInit: true
});

var bindEventHanders = function (that) {
    // When the model changes, update the resulting "converted" value
    that.applier.modelChanged.addListener("amount", function () {
        that.convert(that.model.amount);
    });
    that.applier.modelChanged.addListener("currentSelection", function () {
        that.convert(that.model.amount);
    });
    that.applier.modelChanged.addListener("result", function () {
        that.refreshView();
    });
};

tutorials.currencyConverter.produceTree = function (that) {
    return {
        amount: "${amount}",
        currency: {
            optionnames: "${rates.names}",
            optionlist: "${rates.values}",
            selection: "${currentSelection}"
        },
        result: "${result}"
    };
};

tutorials.currencyConverter.finalInit = function (that) {

    // Add a method to the component object
    that.convert = function (amount) {
        var convertedAmount = parseInt(amount) * that.model.currentSelection;
        that.applier.requestChange("result", convertedAmount);
        that.events.conversionUpdated.fire(convertedAmount);
    };
    
    bindEventHanders(that);
};
Div
classtutorial-linear-nav

Span
classtutorial-nav-left
Previous: Tutorial - View Components
Span
classtutorial-nav-centre
Up to overview
Span
classtutorial-nav-right
Next: Subcomponents