SingletonService

Source singleton-service

This service can be used to create Singleton services, that shares it reference everywhere. (Be aware: this will share services even between dapps that uses the same library! Some Ionic functionallities can have some problems, because runtime references are destroyed after an DApp was closed.).


create

singletonService.create(SingeltonServiceClass, instance, init, updateOnCoreChange);

Creates an single references for services to handle one time service creations and value bindings.

Parameters

  1. SingeltonServiceClass - any: Class object
  2. instance - any: Current instance of an class.
  3. init - Function: Function to run, if the service was created once
  4. updateOnCoreChange - boolean: Run init function, if evan core gets updated

Example

@Injectable()
export class SampleService {
  /**
   * Create a singleton service instance. Start screen size watching. Prefill
   * dev ens variables
   */
  constructor(
    private platform: Platform,
    private singleton: SingletonService
  ) {
    return singleton.create(SampleService, this, () => {
      // doo initialization stuff
    });
  }
}