Versions Compared

Key

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

...

A Enactor is an Infusion component that "acts upon" a preference setting, making whatever adjustments are necessary to enact the preference. There are only a few requirements for an Enactor, since it's its nature is defined determined by the preference it acts upon. For example:

  • the 'text size' enactor provided by the Preferences Framework defines functions that adjust CSS on the page;
  • a 'self-voicing' enactor defined for the GPII Exploration Tool defines functions that use a server-based text-to-speech engine to speak text found on the page.

Enactors defaults must include certain things:

  • the fluid.prefs.enactor grade
  • a preferences map (only when using schemas)

Each of these is explained below.

Grade

Enactors must be defined using the fluid.prefs.enactors grade, as shown on line 2 in the following code block:

Code Block
linenumberstrue
fluid.defaults("my.pref.enactor", {
    gradeNames: ["fluid.prefs.enactors", "autoInit"],
    ...
});

The foo grade is a model component and an evented component, so it Enactors are, by default, model components and evented components, so they automatically provides support for a model and for events. If other support is needed, other grades can be added. For example, if the enactor will be operating on the DOM, the fluid.viewComponent grade should be used, and the selectors option should be provided, as shown in the following example:

...

Code Block
linenumberstrue
// shared grade, defining common functionality
fluid.defaults("my.pref.enactorGrade", {
    gradeNames: ["fluid.prefs.enactors", "autoInit"],
    <common defaults>
});

// one specific enactor, which uses the shared grade
fluid.defaults("my.pref.enactor1", {
    gradeNames: ["my.pref.enactorGrade", "autoInit"],
    <defaults specific to enactor 1>
});

// another specific enactor, which uses the shared grade
fluid.defaults("my.pref.enactor2", {
    gradeNames: ["my.pref.enactorGrade", "autoInit"],
    <defaults specific to enactor 2>
});

Preference Map (Schema Only)

IMPORTANT NOTE: Preference Maps are only required if you are working with schemas and the builder. If you are using grades instead (only necessary in rare cases), you do not need a preference map.

...

Enactors are Infusion model components: They automatically have a top-level property called model which holds the Enactor's internal model representing the preference it acts upon. It is not necessary for you to define this property directly; its structure will be inferred from the preferences map. If you are working with grades instead of with schemas, the model will be inferred from the rules supplied for the Panel. See Using Grades Instead Of Schemas for more information on working with grades.

Examples

...

Code Block
titleExample: Enactor that calls a setter function when the model changes
linenumberstrue
fluid.defaults("gpii.enactor.cursorSize", {
    gradeNames: ["fluid.viewComponent", "fluid.prefs.enactor", "autoInit"],
    preferenceMap: {
        "gpii.primarySchema.cursorSize": {
            "model.value": "default"
        }
    },
    selectors: {
        cursorDiv: ".gpiic-increaseSize-previewPerSettingCursorDiv"
    },
    invokers: {
        set: {
            funcName: "gpii.enactor.cursorSize.set",
            args: ["{that}.model.value", "{that}.dom.cursorDiv"],
            dynamic: true
        }
    },
    listeners: {
        "onCreate.init": {
            listener: "{that}.applier.modelChanged.addListener",
            args: ["value", "{that}.set"]
        }
    }
});

gpii.enactor.cursorSize.set = function (times, cursorDiv) {
    cursorDiv.css("font-size", times + "em");
};
Code Block
titleExample: Enactor that uses a text-to-speech server to self-voice a page
linenumberstrue
fluid.defaults("gpii.explorationTool.enactors.selfVoicing", {
    gradeNames: ["fluid.viewComponent", "fluid.prefs.enactor", "autoInit"],
    model: {
        value: false
    },
    listeners: {
        "afterAnnounce.next": "{that}.announceNext"
    },
    events: {
        afterAnnounce: null,
        onError: null
    },
    invokers: {
        handleSelfVoicing: {
            funcName: "gpii.explorationTool.enactors.selfVoicing.handleSelfVoicing",
            args: "{that}"
        },
        announce: {
            funcName: "gpii.explorationTool.enactors.selfVoicing.announce",
            args: ["{that}", "{arguments}.0"]
        },
        announceNext: {
            funcName: "gpii.explorationTool.enactors.selfVoicing.announceNext",
            args: "{that}"
        }
    },
    members: {
        seen: [],
        speaking: false
    },
    strings: {
        loaded: "text to speech enabled"
    },
    styles: {
        current: "fl-selfVoicing-current"
    },

    // Fireworks Server
    ttsUrl: "http://tts.idrc.ocadu.ca?q=%text",

    lang: "en"
});