From bb3a1b80743fa59da90c3f96cee31e9b138e7432 Mon Sep 17 00:00:00 2001 From: Alex Kanunnikov Date: Sat, 9 Dec 2023 11:39:58 +0300 Subject: [PATCH] ember-concurrency --- src/controllers/application.ts | 15 ++++++++++++++- vite.config.ts | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/controllers/application.ts b/src/controllers/application.ts index 04ab0bb..1a9a998 100644 --- a/src/controllers/application.ts +++ b/src/controllers/application.ts @@ -3,13 +3,26 @@ import { service } from '@ember/service'; import type SessionService from 'ember-simple-auth/addon/services/session'; import type EmberNotify from 'ember-notify'; import { tracked } from '@glimmer/tracking'; +import { restartableTask, timeout } from 'ember-concurrency'; +import type { Task } from 'ember-concurrency'; + +type MyTaskType = Task; + export class ApplicationController extends Controller { @service session: SessionService; @service notify: EmberNotify; @tracked showModal = true; - closeModal = () => { + closeModalTask: MyTaskType = restartableTask(async () => { + await this.notify.info( + `You trying to close modal, let's debounce it for 300ms` + ); + await timeout(300); this.showModal = false; + }); + + closeModal = () => { + this.closeModalTask.perform(); }; constructor(...args: ConstructorParameters) { diff --git a/vite.config.ts b/vite.config.ts index 4395016..8ba1345 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -11,6 +11,7 @@ import refBucketTransform from 'ember-ref-bucket/lib/ref-transform.js'; import { babelHotReloadPlugin } from './plugins/hot-reload'; import { removeLegacyLayout } from './plugins/remove-legacy-layout'; import { dropImportSync } from './plugins/drop-import-sync'; +import emberConcurrencyTransform from 'ember-concurrency/lib/babel-plugin-transform-ember-concurrency-async-tasks'; export default defineConfig(({ mode }) => { const isProd = mode === 'production'; const isDev = mode === 'development'; @@ -424,6 +425,7 @@ function defaultBabelPlugins(isProd: boolean) { }, ], templateCompilationPlugin(isProd), + emberConcurrencyTransform, ]; }