Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BreezeEvent<T>

Class to support basic event publication and subscription semantics.

dynamic

Type parameters

  • T

Hierarchy

  • BreezeEvent

Index

Constructors

constructor

  • new BreezeEvent(name: string, publisher: Object, defaultErrorCallback?: function): BreezeEvent
  • Constructor for an Event

    salaryEvent = new BreezeEvent("salaryEvent", person);

    Parameters

    • name: string

      The name of the event.

    • publisher: Object

      The object that will be doing the publication. i.e. the object to which this event is attached.

    • Optional defaultErrorCallback: function

      Function to call when an error occurs during subscription execution. If omitted then subscriber notification failures will be ignored.

        • (e: Error): any
        • Parameters

          • e: Error

          Returns any

    Returns BreezeEvent

Properties

name

name: string

The name of this Event

publisher

publisher: Object

The object doing the publication. i.e. the object to which this event is attached.

Methods

clear

  • clear(): void
  • remove all subscribers

    Returns void

publish

  • publish(data: T, publishAsync?: boolean, errorCallback?: function): boolean
  • Publish data for this event.

     // Assume 'salaryEvent' is previously constructed Event
     salaryEvent.publish( { eventType: "payRaise", amount: 100 });

    This event can also be published asychronously

     salaryEvent.publish( { eventType: "payRaise", amount: 100 }, true);

    And we can add a handler in case the subscriber 'mishandles' the event.

     salaryEvent.publish( { eventType: "payRaise", amount: 100 }, true, function(error) {
         // do something with the 'error' object
     });

    Parameters

    • data: T

      Data to publish

    • Default value publishAsync: boolean = false

      (default=false) Whether to publish asynchonously or not.

    • Optional errorCallback: function

      Function to be called for any errors that occur during publication. If omitted, errors will be eaten.

        • (e: Error): any
        • Parameters

          • e: Error

          Returns any

    Returns boolean

    false if event is disabled; true otherwise.

publishAsync

  • publishAsync(data: any, errorCallback: function): void
  • Publish data for this event asynchronously.

     // 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.

     salaryEvent.publishAsync( { eventType: "payRaise", amount: 100 }, function(error) {
         // do something with the 'error' object
     });

    Parameters

    • data: any

      Data to publish

    • errorCallback: function

      Function to be called for any errors that occur during publication. If omitted, errors will be eaten.

        • (e: Error): any
        • Parameters

          • e: Error

          Returns any

    Returns void

subscribe

  • subscribe(callback: function): number
  • Subscribe to this event.

     // 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 EntityAspect.propertyChanged, EntityAspect.validationErrorsChanged as well.

     // Assume order is a preexisting 'order' entity
     order.entityAspect.propertyChanged.subscribe(function (pcEvent) {
         if ( pcEvent.propertyName === "OrderDate") {
             // do something
         }
     });

    Parameters

    • callback: function
        • (data: any): any
        • Parameters

          • data: any

            {Object} Whatever 'data' was published. This should be documented on the specific event.

          Returns any

    Returns number

    This is a key for 'unsubscription'. It can be passed to the 'unsubscribe' method.

unsubscribe

  • unsubscribe(unsubKey: number): boolean
  • Unsubscribe from this event.

     // Assume order is a preexisting 'order' entity
     let token = order.entityAspect.propertyChanged.subscribe(function (pcEvent) {
             // do something
     });
     // sometime later
     order.entityAspect.propertyChanged.unsubscribe(token);

    Parameters

    • unsubKey: number

      The value returned from the 'subscribe' method may be used to unsubscribe here.

    Returns boolean

    Whether unsubscription occured. This will return false if already unsubscribed or if the key simply cannot be found.

Static bubbleEvent

  • bubbleEvent(target: any, getParentFn?: function): void
  • event bubbling - document later.

    Parameters

    • target: any
    • Optional getParentFn: function
        • (): any
        • Returns any

    Returns void

Static enable

  • enable(eventName: string, obj: Object, isEnabled: boolean): void
  • Enables or disables the named event for an object and all of its children.

     BreezeEvent.enable(“propertyChanged”, myEntityManager, false)

    will disable all EntityAspect.propertyChanged events within a EntityManager.

     BreezeEvent.enable(“propertyChanged”, myEntityManager, true)

    will enable all EntityAspect.propertyChanged events within a EntityManager.

     BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, false)

    will disable EntityAspect.propertyChanged events for a specific entity.

     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.

     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.

    Parameters

    • eventName: string

      The name of the event.

    • obj: Object
    • isEnabled: boolean

      A boolean, a null or a function that returns either a boolean or a null.

    Returns void

Static isEnabled

  • isEnabled(eventName: string, obj: Object): any
  • Returns whether for a specific event and a specific object and its children, notification is enabled or disabled or not set.

     BreezeEvent.isEnabled(“propertyChanged”, myEntityManager)

    Parameters

    • eventName: string

      The name of the event.

    • obj: Object

    Returns any

    A null is returned if this value has not been set.

Generated using TypeDoc