Versions Compared

Key

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

...

Code Block
javascript
javascript
// Declare the events in the defaults
fluid.defaults("tutorials.recordEditor", {
    gradeNames: ["fluid.eventedComponent", "autoInit"],
    events: {
        afterSave: null,
        onRemove: "preventable",
        afterRemove: null
    },
    finalInitFunction: "tutorials.recordEditor.finalInit"
});

// Add public methods that will fire events when they do things
tutorials.recordEditor.finalInit = function (that) {
    that.save = function () {
        // save stuff
        // ...
        // let anyone listening know the save has happened:
        that.events.afterSave.fire();
    };
    
    that.remove = function () {
        // see if anyone listening objects to the removal:
        var prevent = that.events.onRemove.fire();
        if (prevent === false) {
            // a listener prevented the move,
            // don't do it
        }
        else {
            // no one objects, go ahead and remove
            // ...
            // let listeners know that the remove has completed
            that.events.afterRemove.fire();
        }
    };
};

Next: Model View Components