oracular / endEpisode
Function: endEpisode()
ts
function endEpisode(state, at): EngineState;Defined in: observe.ts:113
Ends the current episode at at. Every intent whose outcome did not arrive gives a miss to each signal seen this episode and counts the episode toward its base rate, or, with IntentConfig.attribution set, holds the episode for the outcome instead. Call it when a session ends: tab closed, app backgrounded, user signed out.
Parameters
| Parameter | Type | Description |
|---|---|---|
state | EngineState | The current state. Not mutated. |
at | number | When the episode ended. If it had already timed out under config.episodeTimeout, it is closed at the moment it timed out instead. |
Returns
The next state with no open episode, or the very same state object when no episode was open.
Throws
TypeError when state is not an engine state or at is not a finite number.
Example
ts
window.addEventListener('pagehide', () => {
state = endEpisode(state, Date.now());
localStorage.setItem('oracular', serialize(state));
});