Home Reference Source
import ReferenceContext from 'reference-context'
public class | source

ReferenceContext

Indirect Subclass:

Context, Library, LocalContext

Example:

import ReferenceContext from 'reference-context';

const context = new ReferenceContext();

Static Method Summary

Static Public Methods
public static

isValidReference(reference: *): boolean

Check if the given reference is valid.

Constructor Summary

Public Constructor
public

constructor(context: object | ReferenceContext | Iterable, parentContext: ReferenceContext | null)

Create a reference-context instance.

Member Summary

Public Members
public get

The the number of values in this context including it's parents.

public get

The the number of values in this context (excluding the parents).

public get

The the number of keys in this context (excluding the parents).

public get

Get the parent context.

public get

The the number of keys in this context including it's parents.

Method Summary

Public Methods
public

assign(value: *): Reference

Assign a new reference for the given value or return it's current reference.

public

clear(): void

Clear and release all the values on this context.

public

Create a closure context for this context.

public

Copy from other context it's references and values

public

delete(reference: Reference): boolean

Remove the given reference from this context.

public

exists(value: *): boolean

Check if this context or one of it's parents has the given value.

public

forEach(callback: function, thisArg: *): ReferenceContext

Iterate over the context own values.

public

Generate a reference for the assign method.

public

get(reference: Reference): * | undefined

Get the reference value on this context or it's parents.

public

has(reference: Reference): boolean

Check if this context or it's parents has the given reference.

public

Check if this context only (and not the parents) has the given reference.

public

lookup(value: *): Reference | undefined

Get the reference of the given value in this context or one of it's parents. Return undefined if the value not exists.

public

own(value: *): boolean

Check if this context only (excluding the parents) has the given value.

public

release(value: *): boolean

Release a value from this context and remove any reference for this value.

public

set(reference: Reference, value: *): ReferenceContext

Set a reference for the given value.

public

Get the instance constructor name.

Static Public Methods

public static isValidReference(reference: *): boolean source

Check if the given reference is valid. All truthy values are valid reference expects true.

Params:

NameTypeAttributeDescription
reference *

The given reference

Return:

boolean

True if it's {Reference}

Public Constructors

public constructor(context: object | ReferenceContext | Iterable, parentContext: ReferenceContext | null) source

Create a reference-context instance.

Params:

NameTypeAttributeDescription
context object | ReferenceContext | Iterable
  • optional

Initialize context with values

parentContext ReferenceContext | null
  • optional

The parent context for this context

Public Members

public get count: number source

The the number of values in this context including it's parents.

public get ownCount: number source

The the number of values in this context (excluding the parents).

public get ownSize: number source

The the number of keys in this context (excluding the parents).

public get parent: ReferenceContext | null source

Get the parent context.

public get size: number source

The the number of keys in this context including it's parents.

Public Methods

public assign(value: *): Reference source

Assign a new reference for the given value or return it's current reference.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

Reference

The generated reference

Throw:

TypeError

If generating references is not supported in this context

public clear(): void source

Clear and release all the values on this context.

Return:

void

public closure(): ReferenceContext source

Create a closure context for this context.

Return:

ReferenceContext

The closure context

public copyFrom(context: ReferenceContext | Map | Array | object): ReferenceContext source

Copy from other context it's references and values

Params:

NameTypeAttributeDescription
context ReferenceContext | Map | Array | object

The context to copy from

public delete(reference: Reference): boolean source

Remove the given reference from this context. If the reference exists only on the parent contexts, this method will do nothing.

Params:

NameTypeAttributeDescription
reference Reference

The given reference

Return:

boolean

True if the reference has been removed

public exists(value: *): boolean source

Check if this context or one of it's parents has the given value.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

boolean

True if it's does.

public forEach(callback: function, thisArg: *): ReferenceContext source

Iterate over the context own values.

Params:

NameTypeAttributeDescription
callback function
thisArg *
  • optional

public generateReference(): Reference source

Generate a reference for the assign method. The reference not required to be unique, the callee is responsible to verify that the reference is not in use and if required call this method again.

Return:

Reference

The generated reference

Throw:

TypeError

If generating references is not supported in this context

public get(reference: Reference): * | undefined source

Get the reference value on this context or it's parents.

Params:

NameTypeAttributeDescription
reference Reference

The reference of the value

Return:

* | undefined

The reference value or undefined

Throw:

ReferenceError

If the reference not exists.

public has(reference: Reference): boolean source

Check if this context or it's parents has the given reference.

Params:

NameTypeAttributeDescription
reference Reference

The given reference

Return:

boolean

True if it's has

public hasOwnReference(reference: Reference): boolean source

Check if this context only (and not the parents) has the given reference.

Params:

NameTypeAttributeDescription
reference Reference

The given reference

Return:

boolean

True if it's has

public lookup(value: *): Reference | undefined source

Get the reference of the given value in this context or one of it's parents. Return undefined if the value not exists.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

Reference | undefined

The value reference or undefined

Throw:

ReferenceError

If the value not exists.

public own(value: *): boolean source

Check if this context only (excluding the parents) has the given value.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

boolean

True if it's does.

public release(value: *): boolean source

Release a value from this context and remove any reference for this value. If the value exists on the parent context, this method will do nothing.

Params:

NameTypeAttributeDescription
value *

The value to release

Return:

boolean

True if the value released from this context

public set(reference: Reference, value: *): ReferenceContext source

Set a reference for the given value.

Params:

NameTypeAttributeDescription
reference Reference

The value reference

value *

The referable value

public toString(): string source

Get the instance constructor name.

Return:

string