Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Div
classfloatRight
Panel
borderColor#ccc
bgColor#fff
titleOn This Page
borderStylesolid
Table of Contents
minLevel32
maxLevel5
Div
classfloatRight
Panel
borderColor#ccc
bgColor#fff
titleSee Also
borderStylesolid

Component Grades
Infusion Event System

...

The Infusion Framework defines its own event system. Infusion events differ from browser events in that they are not bound to the DOM or its insfrastructure. Infusion events can be used for anything, not only user-interface related events.

Declaring an Evented Component

To use events with your component is to use the eventedComponent grade. To do this:

...

  • Event naming conventions: You can call your events anything you like, but Infusion has adopted the convention of prefacing events with on or after to indicate whether or not the event is being fired before some action is taken, or after the action has completed.
  • Event types: By default (the null type), events are fired to everyone listening. You can alternatively select one of two other special cases:
    • unicast: Fired to only the first registered listener.
    • preventable: Listeners can cancel the relevant action and prevent other listeners from hearing about it. In the example above, onAnotherAction is a preventable event.

Example: Saving and Deleting

Suppose you're creating a component that is responsible for managing records of some kind, or editing documents. An application like that is going to allow users to save their edits or remove the record altogether. You might create the following events for these actions:

...

By making the onRemove event preventable, you have the option of carrying out some kind of double-check, like a confirmation dialog, if you like.

Firing Events

When you declare your component to be an evented component, the Framework will automatically set up event firers for all of your listed events. These will be attached to an object on your component called events and provide an API for you to fire events and add or remove listeners.

Example: Saving and Deleting

Our record editor component will likely have public methods for the saving and removing of records. These methods will be responsible for firing the events. We'll add the public methods using the "finalInit" lifecycle hook:

...