Options
All
  • Public
  • Public/Protected
  • All
Menu

A basic pub-sub mechanism for sibling component communication.

example

getting an instance of PubSub

// Obtain a singleton Pub Sub service
const pubSubService = PubSub.getInstance();
example

registering an event

pubSubService.register('click',{
'click': (function() {alert("clicked")})
})
example

unregistering the event

pubSubService.unregister('click',{
'click': (function() {alert("clicked")})
})
example

firing the event

pubSubService.fire('click', 'click', data, 1000)

Hierarchy

Index

Constructors

constructor

  • Returns PubSub

Properties

Private callbacks

callbacks: Map<string, Set<string>> = new Map<string, Set<string>>()

Stores a callback for each event

Static Private instance

instance: PubSub

The instance of this SDK

Accessors

namespace

  • get namespace(): string
  • set namespace(customNamespace: string): void
  • getter method for namespace. Provides the salesforce org namespace

    Returns string

  • setter method for namespace. Set custom namespace

    Parameters

    • customNamespace: string

    Returns void

Methods

fire

  • fire(eventName: any, action: any, payload: any): void
  • Fires an event to listeners.

    Parameters

    • eventName: any

      Name of the event to fire.

    • action: any

      Name of the event to fire.

    • payload: any

      Payload of the event to fire.

    Returns void

register

  • register(eventName: any, callbackobj: any): void
  • Registers a callback for an event

    Parameters

    • eventName: any

      Name of the event to listen for.

    • callbackobj: any

      Contains callback function.

    Returns void

unregister

  • unregister(eventName: any, callbackobj: any): void
  • Unregisters a callback for an event

    Parameters

    • eventName: any

      Name of the event to unregister from.

    • callbackobj: any

      Contains callback function, it should refer to same object which is used to register the event.

    Returns void

version

  • version(): string
  • Returns the version number of SDK.

    Returns string

    Returns SDK version number as string

Static extend

  • extend(extendObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype. .extend should only be used to add new methods and it won't override the existing methods.

    Note: If the property already exists, it will be not be added.

    Custom functions which are being extended should have proper namespaces to avoid issues during upgrades. When Vlocity releases new changes it won't impact if unique namespaces are used.

    Example: myCompanyOrFeatureMethodName

    example

    How to extend an sdk?

    VlocitySDK.datasource.extend({ myCompanySayHello(){
         console.log("Hello World");
      }, sayTime() {
         console.log(new Date().myCompanyGetTime());
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(daSource.myCompanySayHello())

    Parameters

    • extendObj: object

      The object of functions

    Returns void

Static getInstance

  • Get a singleton instance of this PubSub.

    Returns PubSub

    an instance of this SDK.

Static override

  • override(overrideObj: object): void
  • Adds all the enumerable string keyed function properties of a source object to the sdk prototype.

    .override method should only be used to override the existing methods and should only be used in rare cases. Overriding the existing or default methods may cause unintended consequences and may also impact during upgrades.

    Please be cautious while using this

    example

    How to override methods in an sdk?

    VlocitySDK.datasource.override({ soql(){
         console.log("This code overrides the default soql function");
         // code goes here...
      }, sosl() {
         console.log("This code overrides the default soql function");
         // code goes here...
      }});
    
    const dataSource = VlocitySDK.datasource.getInstance({'create':true});
    console.log(dataSource.soql()); // prints "This code overrides the default soql function"

    Parameters

    • overrideObj: object

      The object of functions

    Returns void

Generated using TypeDoc