Group class

View as Markdown

The Group class represents a group. An instance representing the current group is returned calling the group method of Krenalis. For example:

const groupId = krenalis.group().id();

id

The id method is used to get and set the identifier of the group. It always returns the group's identifier, or null if there is no identifier.

To set the group's identifier, call the id method with an argument:

  • to remove the identifier, pass a null argument.
  • to change the identifier, pass a non-empty String or a Number (the number will be converted to a String). If the passed identifier is the same of the current identifier, it does nothing.

Syntax

id(id)
id(id?: string | null): string | null

Parameters

Name Type Required Description
id String or Number Group identifier to set. If it is null, the group's identifier is removed.

Examples

const groupId = krenalis.group().id();
krenalis.group().id(null);
krenalis.group().id('acme');

traits

The traits method is utilized for accessing and modifying the group's traits. It consistently returns the group's traits.

To modify the group's traits, utilize the traits method with an argument:

  • To remove all traits, pass a null argument.
  • To update the traits, provide a non-null object. Since traits are serialized with JSON.stringify, they must consist only of serializable values and should not contain cyclic references. In case of serialization errors, a warning will be logged in the console.

Syntax

traits(traits)
traits(traits?: Record<string, unknown> | null): Record<string, unknown>

Parameters

Name Type Required Description
traits Object Group's traits to set. null to remove all traits.

Examples

const traits = krenalis.group().traits();
krenalis.group().traits(null);
krenalis.group().traits({ name: 'Acme Inc.' });