0.0.2 • Published 5 years ago

@mikazuki/lazy-class v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Lazy Class

GitHub CircleCI npm (scoped)

Lazy evaluation value (class) for JavaScript.

Install

yarn add @mikazuki/lazy-class

How to use

import { AsyncLazy, Lazy } from "@mikazuki/lazy-class";

// sync
const lazy = new Lazy<string>(() => "Hello, World");

lazy.isValueInitialized; // => false
lazy.value; // => "Hello, World"
lazy.isValueInitialized; // => true

// async
const fetch = async () => new Promise(resolve => resolve("Hello, World"));
const asyncLazy = new AsyncLazy<string>(async () => await fetch());

asyncLazy.isValueInitialized; // => false
await asyncLazy.value; // => "Hello, World"
asyncLazy.isValueInitialized; // => true