Module: Proxy
Proxy R objects on the webR worker thread so that they can be accessed from the main thread.
Table of contents
Type Aliases
Functions
Type Aliases
DistProxy
Ƭ DistProxy<U
>: U
extends RObject
? RProxy
<U
> : U
Distributive conditional type for RProxy.
Distributes RProxy over any RObject in the given union type U.
Type parameters
Name | Description |
---|---|
U |
The type union to distribute RProxy over. |
Defined in
webR/proxy.ts:30
Methods
Ƭ Methods<T
>: { [P in keyof T]: T[P] extends Function ? P : never }[keyof T
]
Obtain a union of the keys corresponding to methods of a given class T
.
Type parameters
Name | Description |
---|---|
T |
The type to provide the methods for. |
Defined in
webR/proxy.ts:18
ProxyConstructor
Ƭ ProxyConstructor<T
, R
>: T
extends (…args
: infer U) => any
? (…args
: { [V in string | number | symbol]: U[V] }) => Promise
<R
> : never
& { [P in Methods<typeof RObject>]: RProxify<typeof RObject[P]> }
Create a proxy constructor based on a RObject class.
The class constructors and static methods of the given subclass of RObject are proxied, and the proxied constructor returns a promise to an R object of a given RProxy type.
Type parameters
Name | Description |
---|---|
T |
The type of the RObject class to be proxied. |
R |
The type to be returned from the proxied class constructor. |
Defined in
webR/proxy.ts:90
RProxify
Ƭ RProxify<T
>: T
extends any
[] ? Promise
<DistProxy
<T
[0
]>[]> : T
extends (…args
: infer U) => any
? (…args
: { [V in keyof U]: DistProxy<U[V]> }) => RProxify
<ReturnType
<T
>> : Promise
<DistProxy
<T
>>
Convert RObject properties for use with an RProxy.
Properties in the type parameter T
are mapped so that RProxy is distributed over any RObject types, then wrapped in a Promise.
Function signatures are mapped so that arguments with RObject type instead take RProxy<RObject> type. Other function arguments remain as they are. The function return type is also converted to a corresponding type using RProxify
recursively.
Type parameters
Name | Description |
---|---|
T |
The type to convert. |
Defined in
webR/proxy.ts:46
RProxy
Ƭ RProxy<T
>: { [P in Methods<T>]: RProxify<T[P]> } & { _payload
: WebRPayloadPtr
; [asyncIterator]
: () => AsyncGenerator
<RProxy
<RObject
>, void
, unknown
> }
Create an RProxy based on an RObject type parameter.
R objects created via an RProxy are intended to be used in place of RObject on the main thread. An RProxy object has the same instance methods as the given RObject parameter, with the following differences: * Method arguments take RProxy
in place of RObject.
Where an RObject would be returned, an
RProxy
is returned instead.All return types are wrapped in a Promise.
If required, the WebRPayloadPtr object associated with the proxy can be accessed directly through the _payload
property.
Type parameters
Name | Type | Description |
---|---|---|
T |
extends RObject |
The RObject type to convert into RProxy type. |
Defined in
webR/proxy.ts:75
Functions
newRClassProxy
▸ newRClassProxy<T
, R
>(chan
, shelter
, objType
): ProxyConstructor
<T
, R
>
Proxy an RObject class.
Type parameters
Name | Description |
---|---|
T |
The type of the RObject class to be proxied. |
R |
The type to be returned from the proxied class constructor. |
Parameters
Name | Type | Description |
---|---|---|
chan |
ChannelMain |
The current main thread communication channel. |
shelter |
string |
The shelter ID to protect returned objects with. |
objType |
"string" | "symbol" | "object" | "function" | "double" | "null" | "pairlist" | "closure" | "environment" | "promise" | "call" | "special" | "builtin" | "logical" | "integer" | "complex" | "character" | "dots" | "any" | "list" | "expression" | "bytecode" | "pointer" | "weakref" | "raw" | "s4" | "new" | "free" |
The R object type, or 'object' for the generic RObject class. |
Returns
ProxyConstructor
<T
, R
>
A proxy to the R object subclass corresponding to the given value of the objType
argument.
Defined in
webR/proxy.ts:253
newRProxy
▸ newRProxy(chan
, payload
): RProxy
<RObject
>
Proxy an R object.
The proxy targets a particular R object in WebAssembly memory. Methods of the relevant subclass of RObject are proxied, enabling structured manipulation of R objects from the main thread.
Parameters
Name | Type | Description |
---|---|---|
chan |
ChannelMain |
The current main thread communication channel. |
payload |
WebRPayloadPtr |
A webR payload referencing an R object. |
Returns
An RObject corresponding to the referenced R object.
Defined in
webR/proxy.ts:218
targetMethod
▸ targetMethod(chan
, prop
, payload
): any
Parameters
Name | Type |
---|---|
chan |
ChannelMain |
prop |
string |
payload |
WebRPayloadPtr |
Returns
any
Defined in
webR/proxy.ts:145