-
Notifications
You must be signed in to change notification settings - Fork 6
sp core library.spevent
Home > @microsoft/sp-core-library > SPEvent
Represents a framework event that components can subscribe to.
Signature:
export default class SPEvent<TEventArgs extends SPEventArgs>
Examples of events in a web application might include: the user clicking a button, the system navigating to another page, or an item being added/removed from an abstract collection. The SharePoint Framework represents events using instances of the SPEvent object, one for each kind of event. The SPEvent object is typically exposed as a property of an associated class (e.g. the button that can be clicked). When a component is interested in an event, it calls add() to register an event handler callback that will be invoked each time the event occurs. The handler receives an SPEventArgs parameter that may provide additional details about what happened. This is analogous to the browser's Document Object Model (DOM) events. The main difference is the ISPEventObserver feature, which tracks which component subscribed to each event, and automatically unsubscribes the handler when the component is disposed.
When an event is raised, all handlers are invoked synchronously. The order in which event handlers are called is unspecified. The event handler callback must catch any exceptions that occur during processing; an uncaught exception will not prevent other handlers from executing, but it will be reported as a problem with the associated component.
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the SPEvent
class.
Method | Modifiers | Description |
---|---|---|
add(observer, eventHandler) | Registers a callback that will be invoked whenever the event occurs. | |
remove(observer, eventHandler) | Unregisters a callback that was registered using add(). |