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

Missing composables in global imports #15

Closed
notKamui opened this issue Nov 2, 2023 · 4 comments
Closed

Missing composables in global imports #15

notKamui opened this issue Nov 2, 2023 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@notKamui
Copy link

notKamui commented Nov 2, 2023

As of v0.1.0 of this module, the only auto-imported composable is useStyles (from primevue/usestyles).

However, there are other composables that Primevue provides, notably useToast (from primevue/usetoast), useConfirm (from primevue/useconfirm), or even usePrimeVue.

@mertsincan
Copy link
Member

Hi,

useToast, useConfirm and usePrimeVue is not a composables. They generate globalProperties for components. For example; $primevue from usePrimeVue

Best Regards,

@notKamui
Copy link
Author

Hello,

That is simply not true, per two definitions of composables.

import { inject } from 'vue';

export const PrimeVueToastSymbol = Symbol();

export function useToast() {
    const PrimeVueToast = inject(PrimeVueToastSymbol);

    if (!PrimeVueToast) {
        throw new Error('No PrimeVue Toast provided!');
    }

    return PrimeVueToast;
}

Here's the complete code of useToast for example. Per the naming conventions (use*), it is a composable. Per the fact that it uses the provide/inject by using the inject functions, it is a composable.

If it is not a composable, then it shouldn't be named like so.

In any case, composable or not, I think it would benefit the plugin for these functions to be made available globally, like the other symbols.

Best regards.

@mertsincan mertsincan reopened this Nov 23, 2023
@mertsincan mertsincan added the enhancement New feature or request label Nov 23, 2023
@mertsincan
Copy link
Member

Hello,

I have examined this issue in depth. I noticed that such imports are made as in the 'Explicit Imports' structure. That's why I added all use* structures in the composables file. In order to use your use* structures, you must import as;

import { useToast } from '#imports';

Example App;

<template>
  <div>
    <Toast />
    <Panel header="Header">
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
        irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </Panel>
    <Button label="Show" @click="onShow" />
  </div>
</template>

<script setup>
import { useToast } from '#imports';
const toast = useToast();

const onShow = () => {
  toast.add({
    severity: 'success',
    summary: 'Success Message',
    detail: 'Order submitted',
    life: 3000
  });
};
</script>

Best Regards,

@mertsincan mertsincan added this to the 0.2.1 milestone Nov 23, 2023
@mertsincan mertsincan added bug Something isn't working and removed enhancement New feature or request labels Nov 23, 2023
@th3coop
Copy link

th3coop commented Apr 27, 2024

If anyone else comes across this and like me, the suggested fix doesn't work (probably because I don't understand it), the fix over here resolved the issue for me primefaces/primevue#1442 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants