Many times, you will be creating a component that works in an environment where other things are operating, and it will probably need to notify those other things of key events in its lifecycle. Events can be used to trigger changes in the visual appearance of a component, or actions by other components. For example:
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.
To use events with your component is to use the eventedComponent grade. To do this:
eventsproperty in your defaults, listing the events your component will fire.
The contents of the
events object is a set of key-value pairs where the key is the event name and the value is the event type.
afterto indicate whether or not the event is being fired before some action is taken, or after the action has completed.
nullhere. Event types supported by the framework are described at the Infusion Event System. Another possibility is to inject an event appearing elsewhere in the component tree by use of an IoC reference such as
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
preventable, you have the option of carrying out some kind of double-check, like a confirmation dialog, if you like.
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 (and reference target) for you to fire events and add or remove listeners.
Our record editor component will likely have public methods for the saving and removing of records. We will define these methods using the framework facility for invokers. These methods will be responsible for firing the events.
Component grades can be combined, if necessary. Suppose we wish to add events to the model-bearing currency converter shown on the previous page. We can declare the component to be both a model component and an evented component by using the standard framework grade
fluid.standardComponent which is a built-in defined as the combination of
fluid.modelComponent. The user can define such combinations themselves by just adding the list of grades directly into
During the transition period between Infusion 1.5 and Infusion 2.0 it is recommended that authors of new code use the names
fluid.standardRelayComponent rather than
fluid.standardComponent respectively. See Component Grades for details.
updateCurrency and the model listener). In future versions of Infusion, 100% of this component will be expressible as configuration - it can't be handled by the current framework because of the indirection into the model from itself (the fact that
currency as model indexes). You can track this work at FLUID-5286.