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 RWorker.RObject in the given union type U.
Type parameters
Name | Description |
---|---|
U |
The type union to distribute RProxy over. |
Defined in
webR/proxy.ts:31
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:20
ProxyConstructor
Ƭ ProxyConstructor<T
, R
>: T
extends (…args
: infer U) => any
? (…args
: { [V in string | number | symbol]: U[V<V>] }) => Promise
<R
> : never
& { [P in Methods<typeof RObject>]: RProxify<typeof RObject[P]> }
Create a proxy constructor based on a RWorker.RObject class.
The class constructors and static methods of the given subclass of RWorker.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 RWorker.RObject class to be proxied. |
R |
The type to be returned from the proxied class constructor. |
Defined in
webR/proxy.ts:92
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
>> : T
extends { output
: RObject
; result
: RObject
} ? Promise
<{ [U in keyof T]: DistProxy<T[U]> }> : Promise
<DistProxy
<T
>>
Convert RWorker.RObject properties for use with an RProxy.
Properties in the type parameter T
are mapped so that RProxy is distributed over any RWorker.RObject types, then wrapped in a Promise.
Function signatures are mapped so that arguments with RWorker.RObject type instead take RProxy<RWorker.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 RWorker.RObject type parameter.
R objects created via an RProxy are intended to be used in place of RWorker.RObject on the main thread. An RProxy object has the same instance methods as the given RWorker.RObject parameter, with the following differences: - Method arguments take RProxy
in place of RWorker.RObject.
Where an RWorker.RObject would be returned, an
RProxy
is returned instead.All return types are wrapped in a Promise.
If required, the Payload.WebRPayloadPtr object associated with the proxy can be accessed directly through the _payload
property.
Type parameters
Name | Type | Description |
---|---|---|
T |
extends RObject |
The RWorker.RObject type to convert into RProxy type. |
Defined in
webR/proxy.ts:78
Functions
newRClassProxy
▸ newRClassProxy<T
, R
>(chan
, shelter
, objType
): ProxyConstructor
<T
, R
>
Proxy an RWorker.RObject class.s
Type parameters
Name | Description |
---|---|
T |
The type of the RWorker.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" | "function" | "null" | "pairlist" | "closure" | "environment" | "promise" | "call" | "special" | "builtin" | "logical" | "integer" | "double" | "complex" | "character" | "dots" | "any" | "list" | "expression" | "bytecode" | "pointer" | "weakref" | "raw" | "s4" | "new" | "free" | RCtor |
The R object type or class, 'object' for the generic RWorker.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 RWorker.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:219
targetMethod
▸ targetMethod(chan
, prop
, payload
): unknown
Parameters
Name | Type |
---|---|
chan |
ChannelMain |
prop |
string |
payload |
WebRPayloadPtr |
Returns
unknown
Defined in
webR/proxy.ts:147