Skip to content

oracular / shouldReveal

Function: shouldReveal() ​

ts
function shouldReveal(
   state, 
   intent, 
   at, 
   opts?
): boolean;

Defined in: predict.ts:67

Whether to act on the intent now. True when p ≥ threshold, the lower confidence bound (p − z·sd, or the exact Beta quantile with bound: 'exact') also clears threshold, and no cooldown is running: neither the one started by markRevealed nor the one started by the intent's outcome event.

Parameters ​

ParameterTypeDescription
stateEngineStateThe current state. Not mutated.
intentstringName of an intent declared in the config.
atnumberThe time to evaluate at.
opts?RevealOptionsOverrides for threshold (default 0.5), z (default 1.28, a one-sided 90% bound) and cooldown (default: the intent's halfLife).

Returns ​

boolean

True when the app should show, offer or reveal whatever this intent gates.

Throws ​

RangeError when intent is not declared in the config.

Throws ​

TypeError when state is not an engine state, at is not finite, or opts is malformed.

Example ​

ts
if (shouldReveal(state, 'upgrade', Date.now())) {
  showUpgradeOffer();
  state = markRevealed(state, 'upgrade', Date.now());
}

Released under the MIT License.