Skip to content

Commit

Permalink
More poking, non of this works
Browse files Browse the repository at this point in the history
  • Loading branch information
Windvis committed Nov 26, 2024
1 parent 49de067 commit cc1c18d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
26 changes: 11 additions & 15 deletions addon/services/toaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import { A, type NativeArray } from '@ember/array';
import type { ComponentLike } from '@glint/template';

export type ToastData = {
component?: ComponentLike<CustomToastSignature>;
title?: string;
message?: string;
options: ToastOptions;
options: ToastOptions | Record<string, unknown>;
};

export type CustomToastData = {
component?: ComponentLike<CustomToastSignature>;
options: object;
}

export type ToastOptions = {
icon?: string | ComponentLike<{ Element: Element }>;
closable?: boolean;
Expand All @@ -24,7 +20,7 @@ export type ToastOptions = {

export interface CustomToastSignature {
Args: {
options: object;
options: Record<string, unknown>;
close: () => void;
};
}
Expand All @@ -35,26 +31,26 @@ export default class ToasterService extends Service {
@tracked toasts: NativeArray<ToastData> = A<ToastData>([]);

displayToast = task(async (toast: ToastData) => {
if (typeof toast.options.timeOut === 'undefined') {
toast.options.timeOut = null;
if (typeof toast.options['timeOut'] === 'undefined') {
toast.options['timeOut'] = null;
}

if (typeof toast.options.closable === 'undefined') {
toast.options.closable = true;
if (typeof toast.options['closable'] === 'undefined') {
toast.options['closable'] = true;
}

this.toasts.pushObject(toast);

if (toast.options.timeOut) {
await timeout(toast.options.timeOut);
if (toast.options['timeOut']) {
await timeout(toast.options['timeOut']);

this.close(toast);
}
});

show(
component: ComponentLike<CustomToastSignature>,
options: object = {},
component: ComponentLike<unknown>,
options: Record<string, unknown> = {},
) {
const toast = {
component,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/components/au-toaster-test.gts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ module('Integration | Component | au-toaster', function (hooks) {

const CustomToast: TOC<{
Args: {
options: {
foo: string
};
// options: ToastOptionsWithFoo; // Doesn't work
// options: {
// foo: string
// };
options: ToastOptionsWithFoo; // Doesn't work
// options: ToastOptions; // Works, but fails on the `@options.foo` usage in the template
// options: ToastOptions & { foo: string }; // Doesn't work
close: CustomToastSignature['Args']['close'];
Expand Down

0 comments on commit cc1c18d

Please sign in to comment.