Socket
Socket
Sign inDemoInstall

define-lazy-prop

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

define-lazy-prop

Define a lazily evaluated property on an object

    3.0.0latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
18,062,318
decreased by-15.58%

Weekly downloads

Readme

Source

define-lazy-prop

Define a lazily evaluated property on an object

Useful when the value of a property is expensive to generate, so you want to delay the computation until the property is needed. For example, improving startup performance by deferring nonessential operations.

Install

$ npm install define-lazy-prop

Usage

import defineLazyProperty from 'define-lazy-prop';

const unicorn = {
	// …
};

defineLazyProperty(unicorn, 'rainbow', () => expensiveComputation());

app.on('user-action', () => {
	doSomething(unicorn.rainbow);
});

API

defineLazyProperty(object, propertyName, valueGetter)

object

Type: object

Object to add the property to.

propertyName

Type: string

Name of the property to add.

valueGetter

Type: Function

Called the first time propertyName is accessed. Expected to return a value.

  • lazy-value - Create a lazily evaluated value
  • import-lazy - Import a module lazily
  • p-lazy - Create a lazy promise

Keywords

FAQs

Last updated on 14 Apr 2021

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc