Home Reference Source
import Context from 'remote-context/lib/Context.js'
public class | source

Context

Extends:

ReferenceContextAssignableContext → Context

Direct Subclass:

Library

Example:

import { Context } from 'remote-context';

const context = new Context(envContext);

Static Method Summary

Static Public Methods
public static

isReferable(value: *): boolean

Check if the given value is unique per this environment.

Constructor Summary

Public Constructor
public

constructor(envContext: EnvContext, context: object, opts: object)

Create a new virtual context on the given environment.

Method Summary

Public Methods
public

clear()

public

Fetch a local reference and return a local promise.

public

release(value: *): *

public

remote(stream: Stream, opts: object): RemoteContext

Get the remote context of this context.

public

resolve(value: *): LocalPromise

Resolve a local value and return a local promise to that value.

public

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

Inherited Summary

From class ReferenceContext
public static

isValidReference(reference: *): boolean

Check if the given reference is valid.

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.

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.

From class AssignableContext
public

Static Public Methods

public static isReferable(value: *): boolean source

Check if the given value is unique per this environment. For example the string 'foo' is not referable, but the object { foo: 1 } is referable.

Params:

NameTypeAttributeDescription
value *

The given value to check

Return:

boolean

True if the given value is referable

Public Constructors

public constructor(envContext: EnvContext, context: object, opts: object) source

Create a new virtual context on the given environment.

Override:

AssignableContext#constructor

Params:

NameTypeAttributeDescription
envContext EnvContext

The given environment

context object

The context to create

opts object

Options for AssignableContext.constructor

Public Methods

public clear() source

Clear and release all the values on this context.

Override:

ReferenceContext#clear

public fetch(reference: Reference): LocalPromise source

Fetch a local reference and return a local promise.

Params:

NameTypeAttributeDescription
reference Reference

The local reference to fetch

Return:

LocalPromise

public release(value: *): * 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.

Override:

ReferenceContext#release

Params:

NameTypeAttributeDescription
value *

Return:

*

public remote(stream: Stream, opts: object): RemoteContext source

Get the remote context of this context. A single context can be served to multiple peers, each peer will get a separate copy of the context.

Params:

NameTypeAttributeDescription
stream Stream

a duplex stream to the remote peer context

opts object
  • optional

Options to RemoteSession

Return:

RemoteContext

public resolve(value: *): LocalPromise source

Resolve a local value and return a local promise to that value.

Params:

NameTypeAttributeDescription
value *

The local value to resolve

Return:

LocalPromise

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

Set a reference for the given value.

Override:

ReferenceContext#set

Params:

NameTypeAttributeDescription
reference *
value *

Return:

*