Interface Core

A mediator object that hooks everything together and runs your application.

Index

Properties

Sandbox

Sandbox: SandboxClass

The Sandbox class that will be used when core creates sandbox instances.

extensions

extensions: Readonly<string[]>

Lists all installed extensions.

modules

modules: Readonly<string[]>

Lists all added module ids.

runningModules

runningModules: Readonly<object>

Lists all running module instances by their id.

version

version: Readonly<string>

Returns current justcore's version.

Methods

addModule

  • Adds a module.

    Parameters

    Returns void

createHook

  • Creates a hook from given method.

    Type parameters

    Parameters

    • type: HookType
    • method: T
    • Optional context: any

    Returns T & HookProps

init

  • init(onInit?: Func<void>): void
  • Initializes the core.

    Parameters

    • Optional onInit: Func<void>

    Returns void

onMessage

publishAsync

  • publishAsync<T>(message: T): void
  • Publishes a message asynchronously by scheduling (setTimeout) each message handler to the event loop. That async behavior gives us the following benefits:

    • Each message handler is invoked in dedicated call stack;

    • Loose coupling between publishers and handlers. If you somehow rely on the publishAsync's result, your modules don't work independently from each other.

    • Process of tracing messages won't suffer when message handlers depth increases. Because of the event loop's nature in javascript, each message will be published to all of its handlers first even though some of the handlers might publish a new message along the way, e.g. lets say:

      • Module "A" publishes message "M1"
      • Module "B" subscribes for message "M1" and publishes a new message "M2" when message "M1" comes
      • Module "C" subscribes for message "M1"
      • Module "D" subscribes for message "M2"

        When Module "A" publishes its message "M1", the order of the handlers invoked will be:

        Module "B" -> Module "C" -> Module "D".

    Type parameters

    Parameters

    • message: T

    Returns void

startModule

  • Starts an instance of given module and initializes it.

    Parameters

    Returns void

stopModule

  • stopModule(id: string, instanceId?: string): void
  • Stops a given module instance.

    Parameters

    • id: string
    • Optional instanceId: string

    Returns void

use

  • Schedules a list of extensions for installation.

    Parameters

    Returns void