usePoller
Import
import { mix, usePoller, BoltElement } from 'c/boltage';
Usage
export default class myLwc extends mix( [usePoller, { resolveCondition, wiredMethod, maxIteration, interval }], BoltElement) { }
Methods
initPoller(params) : void
Name | Type | Description |
---|---|---|
resolveCondition | Tuple[Function, string] OR string OR Function | Condition to satisfy before stop polling |
wiredMethod | string | Class property decorated by @wire containing Apex results to poll |
maxIteration | number | Number of polls to execute |
interval | number | Time 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
Name | Type | Description |
---|---|---|
status | OK , POLLING_LIMIT_EXCEEDED | How the poller has ended |
results | Record | Apex wired method results |