https://github.com/gnlow/lazywrap
Lazy-load async properties
https://github.com/gnlow/lazywrap
async decorators lazy lazy-loading typescript
Last synced: 6 months ago
JSON representation
Lazy-load async properties
- Host: GitHub
- URL: https://github.com/gnlow/lazywrap
- Owner: gnlow
- License: mit
- Created: 2020-12-29T00:26:40.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-07-03T12:41:25.000Z (about 4 years ago)
- Last Synced: 2024-12-30T14:48:47.694Z (over 1 year ago)
- Topics: async, decorators, lazy, lazy-loading, typescript
- Language: TypeScript
- Homepage:
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lazywrap
Lazy-load async properties
## Use
```ts
import {Lw, LwInterface} from "https://denopkg.com/gnlow/lazywrap@main/mod.ts"
class User {
@Lw("load") declare id: Lw
async log() {
console.log("id", await this.id)
}
async load() {
await new Promise(r => setTimeout(r, 1000))
this.id = Math.random()
}
}
const user1 = new User
await user1.log()
interface Music {
id: number
title?: string
}
type LwMusic = LwInterface
// Apply `Lw` to optional properties
/*
{
id: number
title: Lw
}
*/
```