DisplayReactor
Defined in: display-reactor.ts:135
DisplayReactor provides automatic type transformations between Candid and display-friendly types, plus optional argument validation.
Type Transformations
Section titled “Type Transformations”bigint→string(for JSON/UI display)Principal→string(text representation)[T] | []→T | null(optional unwrapping)- Small blobs → hex strings
Validation (Optional)
Section titled “Validation (Optional)”Register validators to check arguments before canister calls. Validators receive display types (strings), making them perfect for form validation.
Example
Section titled “Example”import { DisplayReactor } from "@ic-reactor/core"
const reactor = new DisplayReactor<_SERVICE>({ clientManager, canisterId: "...", idlFactory,})
// Optional: Add validationreactor.registerValidator("transfer", ([input]) => { if (!input.to) { return { success: false, issues: [{ path: ["to"], message: "Recipient is required" }] } } return { success: true }})
// Call with display typesawait reactor.callMethod({ functionName: "transfer", args: [{ to: "aaaaa-aa", amount: "100" }], // strings!})Extends
Section titled “Extends”Reactor<A,"display">
Type Parameters
Section titled “Type Parameters”A = BaseActor
The actor service type
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DisplayReactor<
A>(config):DisplayReactor<A>
Defined in: display-reactor.ts:143
Parameters
Section titled “Parameters”config
Section titled “config”Returns
Section titled “Returns”DisplayReactor<A>
Overrides
Section titled “Overrides”Properties
Section titled “Properties”transform
Section titled “transform”
readonlytransform:"display"="display"
Defined in: display-reactor.ts:136
Overrides
Section titled “Overrides”_actor
Section titled “_actor”
readonly_actor:A
Defined in: reactor.ts:44
Phantom type brand for inference - never assigned at runtime
Inherited from
Section titled “Inherited from”clientManager
Section titled “clientManager”clientManager:
ClientManager
Defined in: reactor.ts:46
Inherited from
Section titled “Inherited from”name:
string
Defined in: reactor.ts:47
Inherited from
Section titled “Inherited from”canisterId
Section titled “canisterId”canisterId:
Principal
Defined in: reactor.ts:48
Inherited from
Section titled “Inherited from”service
Section titled “service”service:
ServiceClass
Defined in: reactor.ts:49
Inherited from
Section titled “Inherited from”pollingOptions
Section titled “pollingOptions”pollingOptions:
PollingOptions
Defined in: reactor.ts:50
Inherited from
Section titled “Inherited from”Accessors
Section titled “Accessors”queryClient
Section titled “queryClient”Get Signature
Section titled “Get Signature”get queryClient():
QueryClient
Defined in: reactor.ts:399
Get the query client from clientManager. This is the recommended way to access the query client for direct queries.
Returns
Section titled “Returns”QueryClient
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get agent():
HttpAgent
Defined in: reactor.ts:407
Get the agent from clientManager. This is the recommended way to access the agent for direct calls.
Returns
Section titled “Returns”HttpAgent
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”getCodec()
Section titled “getCodec()”getCodec<
M>(methodName):ActorMethodCodecs<A,M> |null
Defined in: display-reactor.ts:192
Get a codec for a specific method. Returns the args and result codecs for bidirectional transformation.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
The name of the method
Returns
Section titled “Returns”ActorMethodCodecs<A, M> | null
Object with args and result codecs, or null if not found
registerValidator()
Section titled “registerValidator()”registerValidator<
M>(methodName,validator):void
Defined in: display-reactor.ts:228
Register a validator for a specific method. Validators receive display types (strings for Principal/bigint).
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
The name of the method to validate
validator
Section titled “validator”DisplayValidator<A, M>
The validator function receiving display types
Returns
Section titled “Returns”void
Example
Section titled “Example”// input.to is string, input.amount is stringreactor.registerValidator("transfer", ([input]) => { if (!/^\d+$/.test(input.amount)) { return { success: false, issues: [{ path: ["amount"], message: "Must be a valid number" }] } } return { success: true }})unregisterValidator()
Section titled “unregisterValidator()”unregisterValidator<
M>(methodName):void
Defined in: display-reactor.ts:238
Unregister a validator for a specific method.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
Returns
Section titled “Returns”void
hasValidator()
Section titled “hasValidator()”hasValidator<
M>(methodName):boolean
Defined in: display-reactor.ts:245
Check if a method has a registered validator.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
Returns
Section titled “Returns”boolean
validate()
Section titled “validate()”validate<
M>(methodName,args):Promise<ValidationResult>
Defined in: display-reactor.ts:273
Validate arguments without calling the canister. Arguments are in display format (strings for Principal/bigint). Useful for form validation before submission.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
The name of the method
AsDisplayArgs<ActorMethodParameters<A[M]>>
The display-type arguments to validate
Returns
Section titled “Returns”Promise<ValidationResult>
ValidationResult indicating success or failure
Example
Section titled “Example”// Validate form data before submissionconst result = await reactor.validate("transfer", [{ to: formData.recipient, // string amount: formData.amount, // string}])
if (!result.success) { result.issues.forEach(issue => { form.setError(issue.path[0], issue.message) })}callMethodWithValidation()
Section titled “callMethodWithValidation()”callMethodWithValidation<
M>(params):Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Defined in: display-reactor.ts:309
Call a method with async validation support. Use this instead of callMethod() when you have async validators.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”functionName
Section titled “functionName”M
AsDisplayArgs<ActorMethodParameters<A[M]>>
callConfig?
Section titled “callConfig?”CallConfig
Returns
Section titled “Returns”Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Example
Section titled “Example”// Async validator (e.g., check if address is blocked)reactor.registerValidator("transfer", async ([input]) => { const isBlocked = await checkBlocklist(input.to) if (isBlocked) { return { success: false, issues: [{ path: ["to"], message: "Address is blocked" }] } } return { success: true }})
await reactor.callMethodWithValidation({ functionName: "transfer", args: [{ to: "...", amount: "100" }],})getServiceInterface()
Section titled “getServiceInterface()”getServiceInterface():
ServiceClass
Defined in: reactor.ts:86
Get the service interface (IDL.ServiceClass) for this reactor. Useful for introspection and codec generation.
Returns
Section titled “Returns”ServiceClass
The service interface
Inherited from
Section titled “Inherited from”isQueryMethod()
Section titled “isQueryMethod()”isQueryMethod<
M>(methodName):boolean
Defined in: reactor.ts:105
Check if a method is a query method (query or composite_query).
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”methodName
Section titled “methodName”M
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”generateQueryKey()
Section titled “generateQueryKey()”generateQueryKey<
M>(params): readonlyunknown[]
Defined in: reactor.ts:147
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorQueryParams<A, M, "display">
Returns
Section titled “Returns”readonly unknown[]
Inherited from
Section titled “Inherited from”getQueryOptions()
Section titled “getQueryOptions()”getQueryOptions<
M>(params):FetchQueryOptions<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Defined in: reactor.ts:167
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorCallParams<A, M, "display">
Returns
Section titled “Returns”FetchQueryOptions<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Inherited from
Section titled “Inherited from”invalidateQueries()
Section titled “invalidateQueries()”invalidateQueries<
M>(params?):void
Defined in: reactor.ts:214
Invalidate cached queries for this canister. This will mark matching queries as stale and trigger a refetch for any active queries.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params?
Section titled “params?”Partial<ReactorQueryParams<A, M, "display">>
Optional parameters to filter the invalidation
Returns
Section titled “Returns”void
Example
Section titled “Example”// Invalidate all queries for this canisterreactor.invalidateQueries()
// Invalidate only 'getUser' queriesreactor.invalidateQueries({ functionName: 'getUser' })
// Invalidate 'getUser' query for specific userreactor.invalidateQueries({ functionName: 'getUser', args: ['user-1'] })Inherited from
Section titled “Inherited from”callMethod()
Section titled “callMethod()”callMethod<
M>(params):Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Defined in: reactor.ts:254
Call a canister method directly using agent.call() or agent.query(). This is the recommended approach for interacting with canisters.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”Omit<ReactorCallParams<A, M, T>, "queryKey">
Returns
Section titled “Returns”Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Example
Section titled “Example”// Query methodconst result = await reactor.callMethod({ functionName: 'greet', args: ['world'],});
// Update method with optionsconst result = await reactor.callMethod({ functionName: 'transfer', args: [{ to: principal, amount: 100n }], callConfig: { effectiveCanisterId: principal },});Inherited from
Section titled “Inherited from”fetchQuery()
Section titled “fetchQuery()”fetchQuery<
M>(params):Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Defined in: reactor.ts:308
Fetch data from the canister and cache it using React Query. This method ensures the data is in the cache and returns it.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorCallParams<A, M, "display">
Returns
Section titled “Returns”Promise<DisplayOf<OkResult<ActorMethodReturnType<A[M]>>>>
Inherited from
Section titled “Inherited from”getQueryData()
Section titled “getQueryData()”getQueryData<
M>(params):DisplayOf<OkResult<ActorMethodReturnType<A[M]>>> |undefined
Defined in: reactor.ts:318
Get the current data from the cache without fetching.
Type Parameters
Section titled “Type Parameters”M extends string
Parameters
Section titled “Parameters”params
Section titled “params”ReactorQueryParams<A, M, "display">
Returns
Section titled “Returns”DisplayOf<OkResult<ActorMethodReturnType<A[M]>>> | undefined
Inherited from
Section titled “Inherited from”subnetId()
Section titled “subnetId()”subnetId():
Promise<Principal>
Defined in: reactor.ts:379
Get the subnet ID for this canister.
Returns
Section titled “Returns”Promise<Principal>
Inherited from
Section titled “Inherited from”subnetState()
Section titled “subnetState()”subnetState(
options):Promise<ReadStateResponse>
Defined in: reactor.ts:386
Get the subnet state for this canister.
Parameters
Section titled “Parameters”options
Section titled “options”ReadStateOptions
Returns
Section titled “Returns”Promise<ReadStateResponse>