Skip to content

usePoller

Import

import { mix, usePoller, BoltElement } from 'c/bolt';

Usage

export default class myLwc extends mix(
[usePoller, {
resolveCondition,
wiredMethod,
maxIteration,
interval
}],
BoltElement
) { }

Methods

initPoller(params) : void

NameTypeDescription
resolveConditionTuple[Function, string] OR string OR FunctionCondition to satisfy before stop polling
wiredMethodstringClass property decorated by @wire containing Apex results to poll
maxIterationnumberNumber of polls to execute
intervalnumberTime between each poll

Example

Tuple as the resolve condition
export default class myLwc extends mix(
[usePoller, {
resolveCondition: [prop => prop === 'OK', 'status__c'],
wiredMethod: 'apexResults',
maxIteration: 10,
interval: 1000
}],
BoltElement
) {
@api recordId;
@wire(apexMethod, {recordId: '$recordId'})
apexResults;
connectedCallback() {
this.template.addEventListener('polling-end', (detail:{status, response}) => {
if(status === 'OK') // doSomething
if(status === 'POLLING_LIMIT_EXCEEDED') // doSomething
})
}
}
@auraEnabled(cacheable=true)
public static Case[] apexMethod(Id recordId) {
return [SELECT status__c FROM Case WHERE Id =: recordId];
}
String as the resolve condition
export default class myLwc extends mix(
[usePoller, {
resolveCondition: 'isReceived__c',
wiredMethod: 'apexResults',
maxIteration: 10,
interval: 1000
}],
BoltElement
) {
@api recordId;
@wire(apexMethod, {recordId: '$recordId'})
apexResults;
connectedCallback() {
this.template.addEventListener('polling-end', (detail:{status, response}) => {
if(status === 'OK') // doSomething
if(status === 'POLLING_LIMIT_EXCEEDED') // doSomething
})
}
}
@auraEnabled(cacheable=true)
public static Case[] apexMethod(Id recordId) {
return [SELECT isReceived__c FROM Case WHERE Id =: recordId AND isReceived__c = true];
}
Function as the resolve condition
export default class myLwc extends mix(
[usePoller, {
resolveCondition: record => record.status__c === 'OK' ? : 'firstEventReceived__c' : 'secondEventReceived__c',
wiredMethod: 'apexResults',
maxIteration: 10,
interval: 1000
}],
BoltElement
) {
@api recordId;
@wire(apexMethod, {recordId: '$recordId'})
apexResults;
connectedCallback() {
this.template.addEventListener('polling-end', (detail:{status, response}) => {
if(status === 'OK') // doSomething
if(status === 'POLLING_LIMIT_EXCEEDED') // doSomething
})
}
}
@auraEnabled(cacheable=true)
public static Case[] apexMethod(Id recordId) {
return [SELECT firstEventReceived__c, secondEventReceived__c, status__c FROM Case WHERE Id =: recordId AND (firstEventReceived__c = true OR secondEventReceived__c = true)];
}

Attributes

POLLER_PROGRESS : number

Example

<lightning-progress-bar value={POLLER_PROGRESS} />

Events

polling-end @ this

NameTypeDescription
statusOK, POLLING_LIMIT_EXCEEDEDHow the poller has ended
resultsRecordApex wired method results