Options
All
  • Public
  • Public/Protected
  • All
Menu

A ng service which is mainly responsible for providing publish/subscribe Messaging API. You can easily create/publish/subscribe a message topic by using this service. This service uses RxJS's Observable / Subject API as a core engine. Neverthelss, it does not require you to have any background on RxJS since it simplifies the RxJS's API by providing a new way to use it. For example, in RxJS's normal way, you may need to keep a reference to an Subject object all the time in which that the message topic is still active. Moreover, if you have more message topics to handle, you must keep more Subject instance references separately. In spite of that, this service diminishes those struggles by mapping each Subject object instance to a topic name. When you want to interact with those topics, you could simply supply the topic name to this service. For more information, please see methods of this class below.

If you only want to publish/subscribe to a topic. Please see publish and subscribe method below.

author

shiorin, tee4cute

Hierarchy

  • ObservableManager

Index

Constructors

constructor

Properties

Private subjects

subjects: any

Methods

complete

  • complete(name: string): void
  • Close the specified topic name. If there is currently no message topic created or no one subsribing to this topic, this method will do nothing. Otherwise, the subscriber's complete handler function will be triggered. Note that, we use the method name complete instead of close since we try to use the same naming as RxJS does as much as possible.

    Parameters

    • name: string

      The message topic name to close.

    Returns void

containsSubject

  • containsSubject(name: string): boolean
  • To check that there already is RxJS's Subject object bound to the given topic name or not.

    Parameters

    • name: string

      A message topic name to check.

    Returns boolean

createSubject

  • createSubject(name: string): Subject<any>
  • Create a new Subject (or topic) and map it to the given topic name. This method will return the old object instance if the given "name" already exists.

    Parameters

    • name: string

      A message topic name to create Subject.

    Returns Subject<any>

error

  • error(name: string, error: any): void
  • Signal error message to the given topic name. The subscriber's error function will be triggered with the given error passed as a parameter. This method will automatically create the topic if the given topic name is not created yet.

    Parameters

    • name: string

      The message topic name to signal.

    • error: any

      The error message to signal.

    Returns void

getSubject

  • getSubject(name: string): Subject<any>
  • Get the RxJS's Subject object bound to the given topic name.

    Parameters

    • name: string

      A message topic name to get.

    Returns Subject<any>

    Returns null if the given topic name is not created yet.

publish

  • publish(name: string, data: any): void
  • Publish a message (data) to the given topic name. The subscriber's handler function will be triggered with the given data passed as a parameter. This method will automatically create the topic if the given topic name is not created yet.

    Parameters

    • name: string

      The message topic name to publish.

    • data: any

      The message data to publish.

    Returns void

subscribe

  • subscribe(name: string, handler: any, errorHandler?: any, completeHandler?: any): Subscription
  • Subscribe message to the given topic name. This method will automatically create the topic if the given topic name is not created yet.

    Parameters

    • name: string

      A message topic name to subscribe.

    • handler: any

      A message handler function which will be triggered when message arrives.

    • Optional errorHandler: any

      An error handler function which will be triggered when any error occurs on the [[Observer]].

    • Optional completeHandler: any

      A handler function which will be triggered when the topic is closed and not publishes any messages anymore.

    Returns Subscription

    A RxJS's Subscription object returning from Subject.subscribe() method.

Generated using TypeDoc