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

RemoteContext

Extends:

ReferenceContext → RemoteContext

A remote context that will represent the local context of the other peer.

Example:

import { RemoteContext } from 'remote-context';

const remoteContext = new RemoteContext(session, parentContext);

Constructor Summary

Public Constructor
public

constructor(session: RemoteSession, parentContext: ReferenceContext)

Create a remote context with given remote session and environment context.

Member Summary

Public Members
public get

Get the context remote session.

Method Summary

Public Methods
public

clear()

public

closure(): *

public

delete(reference: *): boolean

public

destroy(): void

Clear the context and destroy the context session only if this context IS NOT created via closure.

public

dispatch(value: *): Action

Generate a remote action for dispatching the given value remotely.

public

End the remote session.

public

fetch(reference: Reference, opts: object): RemotePromise

Fetch a remote reference and return a remote promise.

public

Get an RemoteValue instance for the given reference value.

public

on(event: string, listener: function): RemoteContext

Listen to an event on the remote session.

public

once(event: string, listener: function): RemoteContext

Listen once to an event on the remote session.

public

release(value: *): *

public

Remove listener from the remote session.

public

Resolve a remote value and return a remote 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.

Public Constructors

public constructor(session: RemoteSession, parentContext: ReferenceContext) source

Create a remote context with given remote session and environment context.

Override:

ReferenceContext#constructor

Params:

NameTypeAttributeDescription
session RemoteSession

The remote session

parentContext ReferenceContext

The environment context

Public Members

public get session: RemoteSession source

Get the context remote session.

Public Methods

public clear() source

Clear and release all the values on this context.

Override:

ReferenceContext#clear

public closure(): * source

Create a closure context for this context.

Override:

ReferenceContext#closure

Return:

*

public delete(reference: *): boolean source

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

Override:

ReferenceContext#delete

Params:

NameTypeAttributeDescription
reference *

Return:

boolean

public destroy(): void source

Clear the context and destroy the context session only if this context IS NOT created via closure.

Return:

void

public dispatch(value: *): Action source

Generate a remote action for dispatching the given value remotely.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

Action

Throw:

ReferenceError

If the value is not RemoteContext#exists

public end(): RemoteContext source

End the remote session.

Return:

RemoteContext

public fetch(reference: Reference, opts: object): RemotePromise source

Fetch a remote reference and return a remote promise. If the value already fetched, return a remote promise of the same value.

Params:

NameTypeAttributeDescription
reference Reference

The remote reference to fetch

opts object
  • optional

RemotePromise.constructor options

Return:

RemotePromise

public getTarget(reference: Reference): RemoteValue source

Get an RemoteValue instance for the given reference value.

Params:

NameTypeAttributeDescription
reference Reference

The remote reference

Return:

RemoteValue

Throw:

ReferenceError

If the context not RemoteContext#has the given reference

public on(event: string, listener: function): RemoteContext source

Listen to an event on the remote session.

Params:

NameTypeAttributeDescription
event string

The event to listen to

listener function

The listener

Return:

RemoteContext

public once(event: string, listener: function): RemoteContext source

Listen once to an event on the remote session.

Params:

NameTypeAttributeDescription
event string

The event to listen to

listener function

The listener

Return:

RemoteContext

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 removeListener(event: string, listener: function): RemoteContext source

Remove listener from the remote session.

Params:

NameTypeAttributeDescription
event string

The event on the listener

listener function

The listener

Return:

RemoteContext

public resolve(value: *, opts: object): RemotePromise | LocalPromise source

Resolve a remote value and return a remote promise to that value. If the value is not a remote value, return a local promise to the same value.

Params:

NameTypeAttributeDescription
value *

The remote value to resolve

opts object
  • optional

RemoteContext.fetch options

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

Set a reference for the given value.

Override:

ReferenceContext#set

Params:

NameTypeAttributeDescription
reference *
value *

Return:

*