Events
React to events.
Using Programmatic Events
The SDK provides the method sdk.event.on
for binding a callback which you can use to react to events. This page also describes the event types you can listen for.
Listening for events with on
Subscribe to updates for various events using the sdk.event.on
method, providing it a valid event name and a callback function.
Note that all events pertain to the currently-loaded design. While subscribing to events before loading a design will not throw an exception, it is strongly recommended to set up event subscriptions after loading a design.
The on
method is synchronous and returns a callback which can be used to unsubscribe from the event.
Example Usage
Here is an example implementation of a workflow using the event API.
This code allows your application to react to scenarios where irradiance data becomes invalidated due to user interaction, and will re-run the irradiance job programmatically once that happens.
const library = await import('<script_url>');
const sdk = await library.load({ token: '<access_token>' });
const design = await sdk.design.load(designId);
// Run initial irradiance job
await design.runIrradiance();
// Listen to irradiance updates and re-run the job if they are invalid
const unsubscribe = sdk.event.on('irradianceUpdated', ({ roof, panels }) => {
const isInvalid = roof === 'invalid' || panels === 'invalid';
if (isInvalid) {
console.log('Re-running irradiance job after invalidation.');
design.runIrradiance();
}
});
// Unsubscribe when needed:
unsubscribe();
Methods
sdk.event.on
Signature
sdk.event.on(event_name, callback);
Parameters
parameter | type | note |
---|---|---|
event_name (required) | string | will warn you if passed an invalid event name |
callback (required) | function | your callback receives the event state as the first parameter |
Returns
Unsubscribe Callback
function unsubscribe(): void;
Event Names
These are the valid event names for use with the sdk.event.on
method, along with the parameter passed as an object to your callback:
Event Name | callback state parameter |
---|---|
irradianceUpdated | { panels: "invalid" or "complete", roof: "invalid" or "complete" } |
IrradianceUpdated
This event will fire whenever the currently-loaded design's irradiance state changes to either "complete" or "invalid".
Aurora's SDK keeps track of irradiance state for both roofs and panels, so the event will fire if either roof or panels irradiance changes.