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

Emits options not declared; causing errors #283

Open
2 tasks done
Raymondo97 opened this issue Jun 23, 2023 · 3 comments
Open
2 tasks done

Emits options not declared; causing errors #283

Raymondo97 opened this issue Jun 23, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Raymondo97
Copy link

Raymondo97 commented Jun 23, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Have you updated Vue FilePond, FilePond, and all plugins?

  • I have updated FilePond and its plugins

Describe the bug

We have been having issues with vue-filepond in our application. We noticed that in your component, emits are not being defined.

https://v3-migration.vuejs.org/breaking-changes/emits-option.html
"It is highly recommended that you document all the events emitted by each of your components using emits."

If you need more information, let me know. I'd be happy to try providing a reproduction and environment details if it's needed.

Reproduction

No reproduction necessary, at this time.

Environment

- Device:
- OS:
- Broser:
- Vue version:
@Raymondo97 Raymondo97 added the bug Something isn't working label Jun 23, 2023
@Raymondo97 Raymondo97 changed the title [Bug] Emits options not declared; causing errors Jun 23, 2023
@Raymondo97
Copy link
Author

Raymondo97 commented Jun 24, 2023

In looking through your code, I did notice this:

// Map FilePond callback methods to Vue $emitters
      const options = events.reduce((obj, value) => {
        obj[value] = (...args) => {
          this.$emit("input", this._pond ? this._pond.getFiles() : []);
          this.$emit(value.substr(2), ...args);
        };
        return obj;
      }, {});

// Map FilePond callback methods to Vue $emitters

Is this doing the same thing as declaring emits?

EDIT:

I see now that this code is only calling the emits. So I don't think the emit options are correctly being applied to the component's instance.

Also .substr is being deprecated. Instead, you can use .substring. It does the same thing.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

@rikschennink
Copy link
Collaborator

@Raymondo97

Is this doing the same thing as declaring emits?

I think not.

I see now that this code is only calling the emits. So I don't think the emit options are correctly being applied to the component's instance.

This used to work, but now this will probably require copying all the events manually instead of adding them dynamically.

Also .substr is being deprecated. Instead, you can use .substring. It does the same thing.

I know, I'll get around to it eventually.

@Raymondo97
Copy link
Author

Raymondo97 commented Jul 13, 2023

This used to work, but now this will probably require copying all the events manually instead of adding them dynamically.

I would hope that you could add them dynamically. According to Vue docs, it looks like it just needs an array of strings, or an object of where the value of the emit is validation. So I would think you could use the same reduce function to return an array of strings, and add that to the emits declaration.

https://vuejs.org/api/options-state.html#emits

In the application my company is working on, we've noticed that components will occasionally work without emits being declared. But sometimes it creates problems, or doesn't work consistently. So that may be why it was working.

With how we've implemented vue-filepond in our application, the component still works. But we are using defineAsyncComponent to import it, along with a v-once directive, in order to prevent errors.

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

2 participants