Skip to content

Commit 0ae016c

Browse files
committed
feat: 🎸 auto destroy manager via destroy ref
1 parent 314c707 commit 0ae016c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { Inject, Injectable } from '@angular/core';
1+
import { Inject, Injectable, inject, Injector, DestroyRef } from '@angular/core';
22
import { Router } from '@angular/router';
33
import { BindQueryParamsManager } from './bind-query-params-manager';
44
import { BIND_QUERY_PARAMS_OPTIONS } from './options';
55
import { BindQueryParamsOptions, CreateOptions, QueryDefOptions } from './types';
66

77
@Injectable({ providedIn: 'root' })
88
export class BindQueryParamsFactory {
9-
constructor(private router: Router, @Inject(BIND_QUERY_PARAMS_OPTIONS) private options: BindQueryParamsOptions) {}
9+
private router = inject(Router);
10+
private options = inject(BIND_QUERY_PARAMS_OPTIONS);
1011

1112
create<T>(defs: QueryDefOptions<T>[] | QueryDefOptions<T>, createOptions?: CreateOptions): BindQueryParamsManager<T> {
12-
return new BindQueryParamsManager<T>(this.router, defs, this.options, createOptions);
13+
const manager = new BindQueryParamsManager<T>(this.router, defs, this.options, createOptions);
14+
inject(DestroyRef).onDestroy(() => manager.destroy());
15+
16+
return manager;
1317
}
1418
}

‎projects/ngneat/bind-query-params/src/lib/options.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { InjectionToken } from '@angular/core';
2+
import { BindQueryParamsOptions } from './types';
23

3-
export const BIND_QUERY_PARAMS_OPTIONS = new InjectionToken('BIND_QUERY_PARAMS_OPTIONS', {
4+
export const BIND_QUERY_PARAMS_OPTIONS = new InjectionToken<BindQueryParamsOptions>('BIND_QUERY_PARAMS_OPTIONS', {
45
providedIn: 'root',
56
factory() {
67
return {

0 commit comments

Comments
 (0)