⁘ common

BINDINGS

The BINDINGS Singleton is a critical part of the @nkmjs framework. It is used to register & create associations between pretty much anything.

BINDINGS is is primarily used internally to register global association between content types (models) and components/editors (views/controllers), as well as content types (models) and custom serializers/encoders.
It also play a key role in allowing custom @nkmjs modules to integrate their content, operations, components & overrides seamlessly into the @nkmjs ecosystem. (more infos : 02-Extending-NKMjs)

Non-exhaustive context list :

  • data.core.
go to → Members
Class repertoire

The Class repertoire is merely a small collection of methods to register classes on a global level and have them accessible through a string identifier.
This is critical during the process of serialization/de-serialization, as serialized data store its string identifier to be deserialized afterward.

Methods

staticGetClass(p_key) → {function}

Retrieve the class constructor associated with a given string identifier

Parameters:
Name Type Description
p_key string

staticGetClassKey(p_class) → {string}

Retrieve the string identifier associated with a given class constructor, if any. If no identifier could be found, but a UID is present in the class provided, the class will be registered using that UID and its value returned by GetClassKey.

Parameters:
Name Type Description
p_class function

constructor

staticRemoveClass(p_key) → {function}

Removes the class mapped to a given key

Parameters:
Name Type Description
p_key string

staticSetClass(p_key, p_class) → {function}

Map a string identifier to a class constructor.

Parameters:
Name Type Description
p_key string

identifier

p_class function

constructor

Global binding

Collection of method to manipulate the global bindings

Methods

staticGet(p_context, p_key, p_fallback, p_broad)

Retrieve the value associated to a given key, within a given context.

Parameters:
Name Type Default Description
p_context function
p_key function | Object
p_fallback * null

fallback value in case no existing binding is found

p_broad boolean true

Whether or not to look for alternative matches

Examples:
// What's the Ustensil in the Kitchen ?
BINDINGS.Get(Kitchen, Ustensil) == Fork

staticRemove(p_key, p_binding, p_context)

Parameters:
Name Type Description
p_key *
p_binding *
p_context *

staticSet(p_context, p_key, p_binding)

Registers an key-control pair within a given context.

Parameters:
Name Type Description
p_context *

Context where the key:binding will be set

p_key *

key

p_binding *

value to bound to p_key in p_context

Examples:
// Maps Fork to Ustensil, in the Kitchen context
BINDINGS.Set(Kitchen, Ustensil, Fork)

// The binding can then be retrieved using `Get` 
BINDINGS.Get(Kitchen, Ustensil) == Fork
Misc

Methods

staticExpand(p_bindings)

Parameters:
Name Type Description
p_bindings common.helpers.BindingKit
Examples:
//This is what you'll do most of the time in your module's index.js
BINDINGS.Expand(require(`./my-module-bindings`));