Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 1.7 KB

defineIdleProperties.md

File metadata and controls

61 lines (48 loc) · 1.7 KB

defineIdleProperties.mjs

idlize/defineIdleProperties.mjs

Overview

This module provides a defineIdleProperties helper function that allows developers to implement the idle-until-urgent pattern in their code. It's useful when you want to initialize one or more property values during an idle period but ensure they can be initialized immediately as soon as they're referenced.

Exports

Usage

import {defineIdleProperties} from 'idlize/defineIdleProperties.mjs';

class MyClass {
  constructor() {
    // Define a getter for `this.data` whose value is initialized
    // in an idle callback (or immediately if referenced).
    defineIdleProperties(this, {
      data: () => {
        // Run expensive code and return the result...
      },
    });
  }
}

defineIdleProperties

Syntax

defineIdleProperties(obj, props);

Parameters

Name Type Description
obj Object The object on which to define the property.
props Object A dictionary of property names and initialization functions. See the defineIdleProperty documentation for prop and init.