Skip to content
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

fix: use inject function instead of decorator #33

Merged
merged 6 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,7 @@ jobs:
HUSKY_SKIP_INSTALL: true
run: npm ci

- name: Check Conventional Commits
id: check-commits
run: |
echo "commit_message=$(git log -1 --pretty=%B)" >> $GITHUB_ENV
if [[ ! $commit_message =~ ^(docs|chore|ci)(\(.+\))?:\s.+$ ]]; then
echo "is_conventional=false" >> $GITHUB_ENV
else
echo "is_conventional=true" >> $GITHUB_ENV
fi

- name: Lint
if: env.is_conventional == 'true'
run: npm run lint -- @ngxpert/hot-toast

- name: Build library
Expand All @@ -55,7 +44,6 @@ jobs:
run: npm run build

- name: Test
if: env.is_conventional == 'true'
run: npm run test

- name: Release
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [3.1.1-beta.1](https://github.com/ngxpert/hot-toast/compare/v3.1.0...v3.1.1-beta.1) (2024-12-10)


### Bug Fixes

* use inject function instead of decorator ([9b63e61](https://github.com/ngxpert/hot-toast/commit/9b63e614729d9d1807d13d1c9ee4e409c371ef34)), closes [#22](https://github.com/ngxpert/hot-toast/issues/22)

# [3.1.0-beta.3](https://github.com/ngxpert/hot-toast/compare/v3.1.0-beta.2...v3.1.0-beta.3) (2024-12-10)


### Bug Fixes

* use inject function instead of decorator ([9b63e61](https://github.com/ngxpert/hot-toast/commit/9b63e614729d9d1807d13d1c9ee4e409c371ef34)), closes [#22](https://github.com/ngxpert/hot-toast/issues/22)

# [3.1.0](https://github.com/ngxpert/hot-toast/compare/v3.0.2...v3.1.0) (2024-12-10)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, QueryList, ViewChildren } from '@angular/core';
import {
Component,
ChangeDetectionStrategy,
inject,
Input,
QueryList,
ViewChildren,
ChangeDetectorRef,
} from '@angular/core';
import { Subject } from 'rxjs';
import {
HotToastClose,
Expand Down Expand Up @@ -46,7 +54,8 @@ export class HotToastContainerComponent {
private onGroupToggle$ = this._onGroupToggle.asObservable();
private onGroupRefAttached$ = this._onGroupRefAttached.asObservable();

constructor(private cdr: ChangeDetectorRef, private toastService: HotToastService) {}
private cdr = inject(ChangeDetectorRef);
private toastService = inject(HotToastService);

trackById(index: number, toast: Toast<unknown>) {
return toast.id;
Expand All @@ -66,18 +75,18 @@ export class HotToastContainerComponent {
const visibleToasts = this.getVisibleToasts(position);
const index = visibleToasts.findIndex((toast) => toast.id === toastId);
const offset =
index !== -1
? visibleToasts.slice(...(this.defaultConfig.reverseOrder ? [index + 1] : [0, index])).reduce((acc, t, i) => {
const toastsAfter = visibleToasts.length - 1 - i;
return this.defaultConfig.visibleToasts !== 0 && i < visibleToasts.length - this.defaultConfig.visibleToasts
? 0
: acc +
(this.defaultConfig.stacking === 'vertical' || this.isShowingAllToasts
? t.height || 0
: toastsAfter * HOT_TOAST_DEPTH_SCALE + HOT_TOAST_DEPTH_SCALE_ADD) +
HOT_TOAST_MARGIN;
}, 0)
: 0;
index !== -1
? visibleToasts.slice(...(this.defaultConfig.reverseOrder ? [index + 1] : [0, index])).reduce((acc, t, i) => {
const toastsAfter = visibleToasts.length - 1 - i;
return this.defaultConfig.visibleToasts !== 0 && i < visibleToasts.length - this.defaultConfig.visibleToasts
? 0
: acc +
(this.defaultConfig.stacking === 'vertical' || this.isShowingAllToasts
? t.height || 0
: toastsAfter * HOT_TOAST_DEPTH_SCALE + HOT_TOAST_DEPTH_SCALE_ADD) +
HOT_TOAST_MARGIN;
}, 0)
: 0;
return offset;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
OnDestroy,
signal,
ChangeDetectorRef,
inject,
} from '@angular/core';
import { NgClass, NgStyle } from '@angular/common';
import { AnimatedIconComponent } from '../animated-icon/animated-icon.component';
Expand Down Expand Up @@ -79,12 +80,10 @@ export class HotToastGroupItemComponent implements OnChanges, OnInit, AfterViewI
private unlisteners: VoidFunction[] = [];
protected softClosed = false;

constructor(
protected injector: Injector,
protected renderer: Renderer2,
protected ngZone: NgZone,
private cdr: ChangeDetectorRef
) {}
private injector = inject(Injector);
private renderer = inject(Renderer2);
private ngZone = inject(NgZone);
private cdr = inject(ChangeDetectorRef);

get toastBarBaseHeight() {
return this.toastBarBase.nativeElement.offsetHeight;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DoCheck,
ElementRef,
EventEmitter,
inject,
Injector,
Input,
NgZone,
Expand Down Expand Up @@ -97,12 +98,10 @@ export class HotToastComponent implements OnInit, AfterViewInit, OnDestroy, OnCh
private softClosed = false;
private groupRefs: CreateHotToastRef<unknown>[] = [];

constructor(
private injector: Injector,
private renderer: Renderer2,
private ngZone: NgZone,
private cdr: ChangeDetectorRef
) {}
private injector = inject(Injector);
private renderer = inject(Renderer2);
private ngZone = inject(NgZone);
private cdr = inject(ChangeDetectorRef);

get toastBarBaseHeight() {
return this.toastBarBase.nativeElement.offsetHeight;
Expand Down
6 changes: 2 additions & 4 deletions projects/ngxpert/hot-toast/src/lib/hot-toast-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import { Observable } from 'rxjs';
type ToastMethod = 'show' | 'success' | 'error' | 'warning' | 'info' | 'loading';

export class HotToastBuilder<DataType = unknown> {
private options: ToastOptions<DataType>;
private options: ToastOptions<DataType> = {};
private groupChildren: HotToastBuilder<unknown>[] = [];
private toastRef: CreateHotToastRef<DataType>;

constructor(private message: Content, private service: HotToastService) {
this.options = {};
}
constructor(private message: Content, private service: HotToastService) {}

setOptions(options: ToastOptions<DataType>): this {
this.options = { ...this.options, ...options };
Expand Down
2 changes: 0 additions & 2 deletions projects/ngxpert/hot-toast/src/lib/hot-toast-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export class HotToastRef<DataType = DefaultDataType> implements HotToastRefProps
/** Subject for notifying the user that the toast has been closed. */
private _onGroupToggle = new Subject<HotToastGroupEvent>();

private _componentRef: { changeDetectorRef: { detectChanges: () => void } };

constructor(private toast: Toast<DataType>) {}

set data(data: DataType) {
Expand Down
18 changes: 9 additions & 9 deletions projects/ngxpert/hot-toast/src/lib/hot-toast.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, Optional, PLATFORM_ID } from '@angular/core';
import { inject, Injectable, PLATFORM_ID } from '@angular/core';
import { CompRef, Content, isComponent, isTemplateRef, ViewService } from '@ngneat/overview';
import { defer, Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
Expand Down Expand Up @@ -33,15 +33,15 @@ export class HotToastService implements HotToastServiceMethods {
private _defaultGlobalConfig = new ToastConfig();
private _defaultPersistConfig = new ToastPersistConfig();

constructor(
private _viewService: ViewService,
@Inject(PLATFORM_ID) private platformId: string,
@Optional() globalConfig: ToastConfig
) {
if (globalConfig) {
private _viewService = inject(ViewService);
private _platformId = inject(PLATFORM_ID);
private _globalConfig = inject(ToastConfig, { optional: true });

constructor() {
if (this._globalConfig) {
this._defaultGlobalConfig = {
...this._defaultGlobalConfig,
...globalConfig,
...this._globalConfig,
};
}
}
Expand Down Expand Up @@ -269,7 +269,7 @@ export class HotToastService implements HotToastServiceMethods {
* Creates a container component and attaches it to document.body.
*/
private init() {
if (isPlatformServer(this.platformId)) {
if (isPlatformServer(this._platformId)) {
return;
}
this._componentRef = this._viewService
Expand Down