I want to add a feature to this code that if i set a timer for 500ms whenever onValueChange is called and if it is called before those 500ms, it is called again and it stops the previous call execution.
Code
private _initializeProjectList(): void {
this.loadAuthUserData$ = this._store.select(selectAuthUserSuccess);
let uuid = '';
this.loadAuthUserData$.pipe(takeUntil(this._destroyed$)).subscribe((response: UserAuthorizations | null) => {
uuid = response !== null ? response.uuid : '';
});
const _object: ProjectFleetListRequestModel = {
limit: this.limit,
offset: this.offset,
filter: this.searchValue,
isFavorite: this.isActive ? true : false,
userUuid: uuid
};
this.projectFleetListData$ = this._store.select(
selectProjectFleetListSuccess
);
this._store.dispatch(
Action.loadingProjectFleetListtPayload({
reqPayload: _object
})
);
this.projectFleetListData$
.pipe(takeUntil(this._destroyed$))
.subscribe((data) => {
if(data?.response) {
this.total = data.totalCount ?? 0;
this.projectArray = data.response ?? [];
this.loading = false;
}
});
}
onValueChange(value: string): void {
this.searchValue = value;
this._initializeProjectList();
}
Case: When I type AAA non-stop, it first makes call for A, then for AA, and then for AAA. I want if i type AAA in a flow, it makes calls only for AAA.
New contributor
Tamoli is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.