source: trip-planner-front/node_modules/define-lazy-prop/readme.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1# define-lazy-prop [![Build Status](https://travis-ci.org/sindresorhus/define-lazy-prop.svg?branch=master)](https://travis-ci.org/sindresorhus/define-lazy-prop)
2
3> Define a [lazily evaluated](https://en.wikipedia.org/wiki/Lazy_evaluation) property on an object
4
5Useful 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.
6
7
8## Install
9
10```
11$ npm install define-lazy-prop
12```
13
14
15## Usage
16
17```js
18const defineLazyProp = require('define-lazy-prop');
19
20const unicorn = {
21 // …
22};
23
24defineLazyProp(unicorn, 'rainbow', () => expensiveComputation());
25
26app.on('user-action', () => {
27 doSomething(unicorn.rainbow);
28});
29```
30
31
32## API
33
34### defineLazyProp(object, propertyName, fn)
35
36#### object
37
38Type: `Object`
39
40Object to add property to.
41
42#### propertyName
43
44Type: `string`
45
46Name of the property to add.
47
48#### fn
49
50Type: `Function`
51
52Called the first time `propertyName` is accessed. Expected to return a value.
53
54
55## Related
56
57- [lazy-value](https://github.com/sindresorhus/lazy-value) - Create a lazily evaluated value
58- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily
59- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise
60
61
62## License
63
64MIT © [Sindre Sorhus](https://sindresorhus.com)
Note: See TracBrowser for help on using the repository browser.