idlize/defineIdleProperties.mjs
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.
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(obj, props);
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 .
|