new Service( shortName )

Description

Base class for building services that can be turned on and off.

Subclasses should NOT override methods here, except for the constructor. Instead they should register listeners for appropriate events.

Parameters
Name Type Description
shortName string

Custom name portion of this instance.

Examples
class DummyService extends Service {
			
			  constructor(instanceName, dummyArgs) {
			    super(`The ${instanceName}`);
			    this.args = dummyArgs
			    this.on('activate', this.#onActivate)
			      .on('deactivate', this.#onDeactivate);
			  }
			
			  #onActivate = (event) => {
			    // do activate stuff with this.args ...
			  }
			
			  #onDeactivate = (event) => {
			    // do deactivate stuff with this.args ...
			  }
			
			}
			
			// else where ...
			function dummyEventCallback(event, svc) {
			  console.info(`${svc.name}` was ${event}`);
			}
			
			const service = new DummyService('Bob', bobInfo)
			  .on('activated', dummyEventCallback)
			  .on('deactivated', dummyEventCallback);
			service.activate();
			service.deactivate();
Details

Members


logger :NexusHoratio.base.Logger


name :string

Details
string

shortName :string

Details
string

Methods


activate()

Description

Called each time service is activated.

Details

deactivate()

Description

Called each time service is deactivated.

Details

on( eventType, func ) → {NexusHoratio.base.Service}

Description

Attach a function to an eventType.

Parameters
Name Type Description
eventType NexusHoratio.base.Dispatcher~EventType

Event type to connect with.

func NexusHoratio.base.Dispatcher~Handler

Single argument function to call.

Returns

This instance, for chaining.

Details

off( eventType, func ) → {NexusHoratio.base.Service}

Description

Remove all instances of a function registered to an eventType.

Parameters
Name Type Description
eventType NexusHoratio.base.Dispatcher~EventType

Event type to disconnect from.

func NexusHoratio.base.Dispatcher~Handler

Function to remove.

Returns

This instance, for chaining.

Details

allowReactivation( allow ) → {NexusHoratio.base.Service}

Parameters
Name Type Description
allow boolean

Whether to allow this service to be activated when already active.

Returns

This instance, for chaining.

Details

setShortName( shortName ) → {NexusHoratio.base.Service}

Parameters
Name Type Description
shortName string

Custom name portion of this instance.

Returns

This instance, for chaining.

Details

Events


activate

Details

activated

Details

deactivate

Details

deactivated

Details