API Reference
classes
Perspectiveproxy

@coasys/ad4m / Exports / PerspectiveProxy

Class: PerspectiveProxy

Perspective UI proxy object

Convenience object for UIs to interact with a perspective. It is created by some of the methods in the PerspectiveClient class and includes a reference to the PerspectiveClient object that created it.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new PerspectiveProxy(handle, ad4m)

Parameters

NameType
handlePerspectiveHandle
ad4mPerspectiveClient

Defined in

perspectives/PerspectiveProxy.ts:50 (opens in a new tab)

Properties

#client

Private #client: PerspectiveClient

Defined in

perspectives/PerspectiveProxy.ts:44 (opens in a new tab)


#handle

Private #handle: PerspectiveHandle

Defined in

perspectives/PerspectiveProxy.ts:43 (opens in a new tab)


#perspectiveLinkAddedCallbacks

Private #perspectiveLinkAddedCallbacks: LinkCallback[]

Defined in

perspectives/PerspectiveProxy.ts:45 (opens in a new tab)


#perspectiveLinkRemovedCallbacks

Private #perspectiveLinkRemovedCallbacks: LinkCallback[]

Defined in

perspectives/PerspectiveProxy.ts:46 (opens in a new tab)


#perspectiveLinkUpdatedCallbacks

Private #perspectiveLinkUpdatedCallbacks: LinkCallback[]

Defined in

perspectives/PerspectiveProxy.ts:47 (opens in a new tab)


#perspectiveSyncStateChangeCallbacks

Private #perspectiveSyncStateChangeCallbacks: SyncStateChangeCallback[]

Defined in

perspectives/PerspectiveProxy.ts:48 (opens in a new tab)


name

name: string

Given name of the perspective

Defined in

perspectives/PerspectiveProxy.ts:32 (opens in a new tab)


neighbourhood

neighbourhood: NeighbourhoodExpression

If the perspective is shared as a Neighbourhood, this is the Neighbourhood Expression

Defined in

perspectives/PerspectiveProxy.ts:38 (opens in a new tab)


sharedUrl

sharedUrl: string

If the perspective is shared as a Neighbourhood, this is the Neighbourhood URL

Defined in

perspectives/PerspectiveProxy.ts:35 (opens in a new tab)


state

state: PerspectiveState

Returns the state of the perspective *

Defined in

perspectives/PerspectiveProxy.ts:41 (opens in a new tab)


uuid

uuid: string

Unique ID of the perspective

Defined in

perspectives/PerspectiveProxy.ts:29 (opens in a new tab)

Methods

add

add(link, status?): Promise<LinkExpression>

Adds a link to this perspective

Parameters

NameTypeDefault value
linkLinkundefined
statusLinkStatus'shared'

Returns

Promise<LinkExpression>

Defined in

perspectives/PerspectiveProxy.ts:131 (opens in a new tab)


addLinkExpression

addLinkExpression(link, status?): Promise<LinkExpression>

Adds a linkExpression to this perspective

Parameters

NameTypeDefault value
linkLinkExpressionundefined
statusLinkStatus'shared'

Returns

Promise<LinkExpression>

Defined in

perspectives/PerspectiveProxy.ts:151 (opens in a new tab)


addLinks

addLinks(links, status?): Promise<LinkExpression[]>

Adds multiple links to this perspective *

Parameters

NameTypeDefault value
linksLink[]undefined
statusLinkStatus'shared'

Returns

Promise<LinkExpression[]>

Defined in

perspectives/PerspectiveProxy.ts:136 (opens in a new tab)


addListener

addListener(type, cb): Promise<void>

Adds a link listener

Parameters

NameTypeDescription
typePerspectiveListenerTypesCan be 'link-added' or 'link-removed'
cbLinkCallbackCallback function that is called when a link is added to the perspective

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:175 (opens in a new tab)


addSdna

addSdna(name, sdnaCode, sdnaType): Promise<boolean>

Adds the given Social DNA code to the perspective's SDNA code

Parameters

NameType
namestring
sdnaCodestring
sdnaType"subject_class" | "flow" | "custom"

Returns

Promise<boolean>

Defined in

perspectives/PerspectiveProxy.ts:330 (opens in a new tab)


addSyncStateChangeListener

addSyncStateChangeListener(cb): Promise<void>

Adds a sync state listener

Parameters

NameTypeDescription
cbSyncStateChangeCallbackCallback function that is called when the sync state of the perspective changes

Returns

Promise<void>

A function that can be called to remove the listener

Defined in

perspectives/PerspectiveProxy.ts:189 (opens in a new tab)


availableFlows

availableFlows(exprAddr): Promise<string[]>

Returns all Social DNA flows that can be started from the given expression

Parameters

NameType
exprAddrstring

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:279 (opens in a new tab)


createExpression

createExpression(content, languageAddress): Promise<string>

Parameters

NameType
contentany
languageAddressstring

Returns

Promise<string>

Defined in

perspectives/PerspectiveProxy.ts:167 (opens in a new tab)


createSubject

createSubject<T>(subjectClass, exprAddr): Promise<T>

Creates a new subject instance by running its (SDNA defined) constructor, which means adding links around the given expression address so that it conforms to the given subject class.

Type parameters

Name
T

Parameters

NameTypeDescription
subjectClassTEither a string with the name of the subject class, or an object with the properties of the subject class. In the latter case, the first subject class that matches the given properties will be used.
exprAddrstringThe address of the expression to be turned into a subject instance

Returns

Promise<T>

Defined in

perspectives/PerspectiveProxy.ts:366 (opens in a new tab)


ensureSDNASubjectClass

ensureSDNASubjectClass(jsClass): Promise<void>

Takes a JS class (its constructor) and assumes that it was decorated by the

Parameters

NameType
jsClassany

Returns

Promise<void>

Subject Class

etc. decorators. It then tests if there is a subject class already present in the perspective's SDNA that matches the given class. If there is no such class, it gets the JS class's SDNA by calling its static generateSDNA() function and adds it to the perspective's SDNA.

Defined in

perspectives/PerspectiveProxy.ts:567 (opens in a new tab)


executeAction

executeAction(actions, expression, parameters): Promise<void>

Parameters

NameType
actionsany
expressionany
parametersParameter[]

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:68 (opens in a new tab)


expressionsInFlowState

expressionsInFlowState(flowName, flowState): Promise<string[]>

Returns all expressions in the given state of given Social DNA flow

Parameters

NameType
flowNamestring
flowStatenumber

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:293 (opens in a new tab)


flowActions

flowActions(flowName, exprAddr): Promise<string[]>

Returns available action names, with regard to Social DNA flow and expression's flow state

Parameters

NameType
flowNamestring
exprAddrstring

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:305 (opens in a new tab)


flowState

flowState(flowName, exprAddr): Promise<number>

Returns the given expression's flow state with regard to given Social DNA flow

Parameters

NameType
flowNamestring
exprAddrstring

Returns

Promise<number>

Defined in

perspectives/PerspectiveProxy.ts:299 (opens in a new tab)


get

get(query): Promise<LinkExpression[]>

Returns all the links of this perspective that matches the LinkQuery

Parameters

NameType
queryLinkQuery

Returns

Promise<LinkExpression[]>

Defined in

perspectives/PerspectiveProxy.ts:121 (opens in a new tab)


getAllSubjectInstances

getAllSubjectInstances<T>(subjectClass): Promise<T[]>

Returns all subject instances of the given subject class as proxy objects.

Type parameters

Name
T

Parameters

NameTypeDescription
subjectClassTEither a string with the name of the subject class, or an object with the properties of the subject class. In the latter case, all subject classes that match the given properties will be used.

Returns

Promise<T[]>

Defined in

perspectives/PerspectiveProxy.ts:433 (opens in a new tab)


getAllSubjectProxies

getAllSubjectProxies<T>(subjectClass): Promise<T[]>

Returns all subject proxies of the given subject class.

Type parameters

Name
T

Parameters

NameTypeDescription
subjectClassTEither a string with the name of the subject class, or an object with the properties of the subject class. In the latter case, all subject classes that match the given properties will be used.

Returns

Promise<T[]>

Defined in

perspectives/PerspectiveProxy.ts:455 (opens in a new tab)


getExpression

getExpression(expressionURI): Promise<ExpressionRendered>

Parameters

NameType
expressionURIstring

Returns

Promise<ExpressionRendered>

Defined in

perspectives/PerspectiveProxy.ts:163 (opens in a new tab)


getNeighbourhoodProxy

getNeighbourhoodProxy(): NeighbourhoodProxy

Returns

NeighbourhoodProxy

Defined in

perspectives/PerspectiveProxy.ts:578 (opens in a new tab)


getSdna

getSdna(): Promise<string[]>

Returns the perspective's Social DNA code This will return all SDNA code elements in an array.

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:321 (opens in a new tab)


getSingleTarget

getSingleTarget(query): Promise<string | void>

Convenience function to get the target of the first link that matches the given query This makes sense when the query is expected to return only one link and the target of that link is what you are looking for.

Works best together with

Parameters

NameType
queryLinkQuery

Returns

Promise<string | void>

Member

setSingelTarget()

Defined in

perspectives/PerspectiveProxy.ts:241 (opens in a new tab)


getSubjectProxy

getSubjectProxy<T>(base, subjectClass): Promise<T>

For an existing subject instance (existing in the perspective's links) this function returns a proxy object that can be used to access the subject's properties and methods.

Type parameters

Name
T

Parameters

NameTypeDescription
basestringURI of the subject's root expression
subjectClassTEither a string with the name of the subject class, or an object with the properties of the subject class. In the latter case, the first subject class that matches the given properties will be used.

Returns

Promise<T>

Defined in

perspectives/PerspectiveProxy.ts:418 (opens in a new tab)


infer

infer(query): Promise<any>

Runs a Prolog query on the perspective's Prolog engine

Parameters

NameType
querystring

Returns

Promise<any>

Defined in

perspectives/PerspectiveProxy.ts:126 (opens in a new tab)


isSubjectInstance

isSubjectInstance<T>(expression, subjectClass): Promise<boolean>

Checks if the given expression is a subject instance of the given subject class

Type parameters

Name
T

Parameters

NameTypeDescription
expressionstringThe expression to be checked
subjectClassTEither a string with the name of the subject class, or an object with the properties of the subject class. In the latter case, the first subject class that matches the given properties will be used.

Returns

Promise<boolean>

Defined in

perspectives/PerspectiveProxy.ts:403 (opens in a new tab)


linkMutations

linkMutations(mutations, status?): Promise<LinkExpressionMutations>

Adds and removes multiple links from this perspective *

Parameters

NameTypeDefault value
mutationsLinkMutationsundefined
statusLinkStatus'shared'

Returns

Promise<LinkExpressionMutations>

Defined in

perspectives/PerspectiveProxy.ts:146 (opens in a new tab)


loadSnapshot

loadSnapshot(snapshot): Promise<void>

Take and load all the links from the given snapshot

Parameters

NameType
snapshotPerspective

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:222 (opens in a new tab)


remove

remove(link): Promise<{ perspectiveRemoveLink: boolean }>

Parameters

NameType
linkLinkExpressionInput

Returns

Promise<{ perspectiveRemoveLink: boolean }>

Defined in

perspectives/PerspectiveProxy.ts:159 (opens in a new tab)


removeLinks

removeLinks(links): Promise<LinkExpression[]>

Removes multiple links from this perspective *

Parameters

NameType
linksLinkExpressionInput[]

Returns

Promise<LinkExpression[]>

Defined in

perspectives/PerspectiveProxy.ts:141 (opens in a new tab)


removeListener

removeListener(type, cb): Promise<void>

Removes a previously added link listener

Parameters

NameTypeDescription
typePerspectiveListenerTypesCan be 'link-added' or 'link-removed'
cbLinkCallbackCallback function that is called when a link is added to the perspective

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:197 (opens in a new tab)


removeSubject

removeSubject<T>(subjectClass, exprAddr): Promise<void>

Removes a subject instance by running its (SDNA defined) destructor, which means removing links around the given expression address

Type parameters

Name
T

Parameters

NameTypeDescription
subjectClassTEither a string with the name of the subject class, or an object with the properties of the subject class. In the latter case, the first subject class that matches the given properties will be used.
exprAddrstringThe address of the expression to be turned into a subject instance

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:386 (opens in a new tab)


runFlowAction

runFlowAction(flowName, exprAddr, actionName): Promise<void>

Runs given Social DNA flow action

Parameters

NameType
flowNamestring
exprAddrstring
actionNamestring

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:311 (opens in a new tab)


sdnaFlows

sdnaFlows(): Promise<string[]>

Returns all the Social DNA flows defined in this perspective

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:273 (opens in a new tab)


setSingleTarget

setSingleTarget(link, status?): Promise<void>

Convenience function to ensure there is only one link with given source and predicate This function will remove all links with the same source and predicate as the given link, and then add the given link. This ensures there is only one target for the given source and predicate.

Works best together with

Parameters

NameTypeDefault value
linkLinkundefined
statusLinkStatus'shared'

Returns

Promise<void>

Member

getSingleTarget()

Defined in

perspectives/PerspectiveProxy.ts:257 (opens in a new tab)


snapshot

snapshot(): Promise<Perspective>

Create and return a snapshot of this perspective A snapshot is a rendered Perspectie object that contains all the links of the perspective.

Returns

Promise<Perspective>

Defined in

perspectives/PerspectiveProxy.ts:217 (opens in a new tab)


startFlow

startFlow(flowName, exprAddr): Promise<void>

Starts the Social DNA flow

Parameters

NameTypeDescription
flowNamestringon the expression
exprAddrstring

Returns

Promise<void>

Defined in

perspectives/PerspectiveProxy.ts:285 (opens in a new tab)


stringOrTemplateObjectToSubjectClass

stringOrTemplateObjectToSubjectClass<T>(subjectClass): Promise<string>

Type parameters

Name
T

Parameters

NameType
subjectClassT

Returns

Promise<string>

Defined in

perspectives/PerspectiveProxy.ts:343 (opens in a new tab)


subjectClasses

subjectClasses(): Promise<string[]>

Returns all the Subject classes defined in this perspectives SDNA

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:335 (opens in a new tab)


subjectClassesByTemplate

subjectClassesByTemplate(obj): Promise<string[]>

Returns all subject classes that match the given template object. This function looks at the properties of the template object and its setters and collections to create a Prolog query that finds all subject classes that would be converted to a proxy object with exactly the same properties and collections.

Since there could be multiple subject classes that match the given criteria, this function returns a list of class names.

Parameters

NameTypeDescription
objobjectThe template object

Returns

Promise<string[]>

Defined in

perspectives/PerspectiveProxy.ts:482 (opens in a new tab)


update

update(oldLink, newLink): Promise<LinkExpression>

Parameters

NameType
oldLinkLinkExpressionInput
newLinkLink

Returns

Promise<LinkExpression>

Defined in

perspectives/PerspectiveProxy.ts:155 (opens in a new tab)