From b00a3aa7d6a9213e6ec71cad615d5b7bd0e35aeb Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Wed, 13 Jul 2022 16:45:48 +0200 Subject: [PATCH] chore(plugins): use return provide --- src/runtime/plugins/clipboard.client.ts | 8 ++- src/runtime/plugins/toast.client.ts | 74 +++++++++++++------------ 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/src/runtime/plugins/clipboard.client.ts b/src/runtime/plugins/clipboard.client.ts index 61b92796..9dc9a02f 100644 --- a/src/runtime/plugins/clipboard.client.ts +++ b/src/runtime/plugins/clipboard.client.ts @@ -24,9 +24,11 @@ export default defineNuxtPlugin((nuxtApp) => { }) } - nuxtApp.provide('clipboard', { - copy - }) + return { + provide: { + copy + } + } }) declare module '#app' { diff --git a/src/runtime/plugins/toast.client.ts b/src/runtime/plugins/toast.client.ts index bad340bc..5ef98905 100644 --- a/src/runtime/plugins/toast.client.ts +++ b/src/runtime/plugins/toast.client.ts @@ -2,7 +2,7 @@ import { Ref } from 'vue' import { defineNuxtPlugin, useState } from '#app' import { ToastNotification, ToastPlugin } from '../types' -export default defineNuxtPlugin((nuxtApp) => { +export default defineNuxtPlugin(() => { const notifications: Ref = useState('notifications', () => []) function addNotification (notification: Partial) { @@ -23,42 +23,44 @@ export default defineNuxtPlugin((nuxtApp) => { notifications.value = notifications.value.filter((n: ToastNotification) => n.id !== id) } - nuxtApp.provide('toast', { - addNotification, - removeNotification, - success ({ title, description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { - addNotification({ - type: 'success', - title, - description, - timeout - }) - }, - info ({ title, description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { - addNotification({ - type: 'info', - title, - description, - timeout - }) - }, - warning ({ title, description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { - addNotification({ - type: 'warning', - title, - description, - timeout - }) - }, - error ({ title = 'An error occurred!', description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { - addNotification({ - type: 'error', - title, - description, - timeout - }) + return { + provide: { + addNotification, + removeNotification, + success ({ title, description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { + addNotification({ + type: 'success', + title, + description, + timeout + }) + }, + info ({ title, description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { + addNotification({ + type: 'info', + title, + description, + timeout + }) + }, + warning ({ title, description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { + addNotification({ + type: 'warning', + title, + description, + timeout + }) + }, + error ({ title = 'An error occurred!', description, timeout }: { title?: string, description?: string, timeout?: number } = {}) { + addNotification({ + type: 'error', + title, + description, + timeout + }) + } } - }) + } }) declare module '#app' {