NarraLeaf

Namespace\<T extends NameSpaceContent\<keyof T\>\>

Namespace is a class that represents a namespace of a Storable

Every write through set, assign or reset is reported to the store it is registered in, so a host can react to it — see Watching stored values. Subscribe on the Storable, not here: newGame() and loading a save both replace the Namespace objects.

Public Properties

name

  • string - Human-readable name of the namespace

Public Methods

constructor

  • name: string - Human-readable name of the namespace
  • initContent: T - Initial content of the namespace
  • key?: string - The namespace key, default is the name

set<Key extends keyof T>

Example:

const namespace = new Namespace<{name: string}>('player1', {name: 'John Doe'});

namespace.set('name', 'Jane Smith');
  • key: Key - The key of the value to set
  • value: T[Key] - The value to set
  • Returns this

get<Key extends keyof T = any>

  • key: Key - The key of the value to get
  • Returns T[Key]

equals<Key extends keyof T = any>

  • key: Key - The key of the value to compare
  • value: T[Key] - The value to compare
  • Returns boolean

assign

  • values: Partial<T> - The content to assign
  • Returns this

has

  • key: keyof T - The key to check
  • Returns boolean

keys

  • Returns (keyof T)[]

values

  • Returns T[keyof T][]

entries

  • Returns [keyof T, T[keyof T]][]

reset

Reset the namespace to its initial content

  • Returns this

On this page