Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.6k
refactor(angular): simplify lazy table initialization#6560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/angular-table': patch | ||
| --- | ||
| Simplify lazy initialization for injected table instances |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { | ||
| DestroyRef, | ||
| assertInInjectionContext, | ||
| inject, | ||
| untracked, | ||
| } from '@angular/core' | ||
| export function injectLazyInit<T extends object>( | ||
| initializer: () => T, | ||
| cleanup: (object: T) => void, | ||
| ): T { | ||
| assertInInjectionContext(injectLazyInit) | ||
| const destroyRef = inject(DestroyRef) | ||
| let object: T | null = null | ||
| const getObject = () => { | ||
| if (object === null) { | ||
| const initializedObject = untracked(initializer) | ||
| object = initializedObject | ||
| if (!destroyRef.destroyed) { | ||
| destroyRef.onDestroy(() => cleanup(initializedObject)) | ||
| } | ||
| } | ||
| return object | ||
| } | ||
| return new Proxy<T>({} as T, { | ||
| get(_, prop, receiver) { | ||
| return Reflect.get(getObject(), prop, receiver) | ||
| }, | ||
| has(_, prop) { | ||
| return Reflect.has(getObject(), prop) | ||
| }, | ||
| ownKeys() { | ||
| return Reflect.ownKeys(getObject()) | ||
| }, | ||
| getOwnPropertyDescriptor() { | ||
| return { | ||
| enumerable: true, | ||
| configurable: true, | ||
| } | ||
| }, | ||
riccardoperra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }) | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.