/** Class to support basic event publication and subscription semantics. */ export declare class BreezeEvent { /** * Called with any exception a subscriber throws that nothing else has handled - that is, when * neither `publish` nor the event was given an error callback. * * It logs to `console.error` by default. Set your own to route it into a logger, or `null` to * go back to discarding these silently (which is what Breeze did before 3.0, and why handler * bugs were so hard to find). * * ```ts * BreezeEvent.unhandledErrorCallback = e => myLogger.error(e); * BreezeEvent.unhandledErrorCallback = null; // say nothing * ``` */ static unhandledErrorCallback: ((e: Error) => void) | null; /** The name of this Event */ name: string; /** The object doing the publication. i.e. the object to which this event is attached. */ publisher: Object; /** Constructor for an Event ```ts salaryEvent = new BreezeEvent("salaryEvent", person); ``` @param name - The name of the event. @param publisher - The object that will be doing the publication. i.e. the object to which this event is attached. @param defaultErrorCallback - Function to call when an error occurs during subscription execution. If omitted then subscriber notification failures will be ignored. */ constructor(name: string, publisher: Object, defaultErrorCallback?: (e: Error) => any); /** Publish data for this event. ```ts // Assume 'salaryEvent' is previously constructed Event salaryEvent.publish( { eventType: "payRaise", amount: 100 }); ``` This event can also be published asychronously ```ts salaryEvent.publish( { eventType: "payRaise", amount: 100 }, true); ``` And we can add a handler in case the subscriber 'mishandles' the event. ```ts salaryEvent.publish( { eventType: "payRaise", amount: 100 }, true, function(error) { // do something with the 'error' object }); ``` @param data - Data to publish @param publishAsync - (default=false) Whether to publish asynchonously or not. @param errorCallback - Function to be called for any errors that occur during publication. If omitted, errors will be eaten. @returns false if event is disabled; true otherwise. */ publish(data: T, publishAsync?: boolean, errorCallback?: (e: Error) => any): boolean; /** Publish data for this event asynchronously. ```ts // Assume 'salaryEvent' is previously constructed Event salaryEvent.publishAsync( { eventType: "payRaise", amount: 100 }); ``` And we can add a handler in case the subscriber 'mishandles' the event. ```ts salaryEvent.publishAsync( { eventType: "payRaise", amount: 100 }, function(error) { // do something with the 'error' object }); ``` @param data - Data to publish @param errorCallback - Function to be called for any errors that occur during publication. If omitted, errors will be eaten. */ publishAsync(data: T, errorCallback: (e: Error) => any): void; /** Subscribe to this event. ```ts // Assume 'salaryEvent' is previously constructed Event salaryEvent.subscribe(function (eventArgs) { if (eventArgs.eventType === "payRaise") { // do something } }); ``` There are several built in Breeze events, such as {@link EntityAspect.propertyChanged}, {@link EntityAspect.validationErrorsChanged} as well. ```ts // Assume order is a preexisting 'order' entity order.entityAspect.propertyChanged.subscribe(function (pcEvent) { if ( pcEvent.propertyName === "OrderDate") { // do something } }); ``` @param callback - Called whenever data is published for this event, with that data as its argument. What is published is documented on each specific event. @returns This is a key for 'unsubscription'. It can be passed to the 'unsubscribe' method. */ subscribe(callback: (data: T) => any): number; /** Unsubscribe from this event. ```ts // Assume order is a preexisting 'order' entity let token = order.entityAspect.propertyChanged.subscribe(function (pcEvent) { // do something }); // sometime later order.entityAspect.propertyChanged.unsubscribe(token); ``` @param unsubKey - The value returned from the 'subscribe' method may be used to unsubscribe here. @returns Whether unsubscription occured. This will return false if already unsubscribed or if the key simply cannot be found. */ unsubscribe(unsubKey: number): boolean; /** remove all subscribers */ clear(): void; /** event bubbling - document later. */ static bubbleEvent(target: any, getParentFn?: (() => any)): void; /** Enables or disables the named event for an object and all of its children. ```ts BreezeEvent.enable(“propertyChanged”, myEntityManager, false) ``` will disable all EntityAspect.propertyChanged events within a EntityManager. ```ts BreezeEvent.enable(“propertyChanged”, myEntityManager, true) ``` will enable all EntityAspect.propertyChanged events within a EntityManager. ```ts BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, false) ``` will disable EntityAspect.propertyChanged events for a specific entity. ```ts BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, null) ``` will removes any enabling / disabling at the entity aspect level so now any 'Event.enable' calls at the EntityManager level, made either previously or in the future, will control notification. ```ts BreezeEvent.enable(“validationErrorsChanged”, myEntityManager, function(em) { return em.customTag === “blue”; }) ``` will either enable or disable myEntityManager based on the current value of a ‘customTag’ property on myEntityManager. Note that this is dynamic, changing the customTag value will cause events to be enabled or disabled immediately. @param eventName - The name of the event. @param obj - The object at which enabling or disabling will occur. All event notifications that occur to this object or children of this object will be enabled or disabled. @param isEnabled - A boolean, a null or a function that returns either a boolean or a null. */ static enable(eventName: string, obj: Object, isEnabled: boolean | ((x: any) => boolean)): void; /** Returns whether for a specific event and a specific object and its children, notification is enabled or disabled or not set. ```ts BreezeEvent.isEnabled(“propertyChanged”, myEntityManager) ``` @param eventName - The name of the event. @param obj - The object for which we want to know if notifications are enabled. @returns Whether notifications are enabled. If nothing is set on the object, the answer comes from its parent chain, and defaults to true. */ static isEnabled(eventName: string, obj: Object): boolean; }