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

Namespace methods (and maybe other filters) #52

Closed
kball opened this issue Sep 7, 2018 · 8 comments
Closed

Namespace methods (and maybe other filters) #52

kball opened this issue Sep 7, 2018 · 8 comments
Labels

Comments

@kball
Copy link

kball commented Sep 7, 2018

The array filters are implemented as methods in a mixin, which can cause problems if the names collide with methods in other components or mixins. (I just spent a couple hours tracking down why a 3rd party component wasn't working, and turned out they had a prop named filterBy that was getting clobbered by the filterBy method from vue-filters.

The names used are pretty common, so this is likely to cause many issues when you mix in the filters globally (as you do in Nuxt with a plugin).

Probably the best solution would be to namespace all the methods so they are unlikely to collide. E.g. vfOrderBy instead of orderBy. This could be optional so those who don't need it (they're using filters locally in a component instead of globally in an app) wouldn't have to use it.

@erikverbeek
Copy link

I just had the same issue using vue-select@2.5.0 which also uses the filterBy name for a method. Managed to fix it by pulling the filterBy method from the package and build in in manually where I needed it and removed the package.

@t0n1zz
Copy link

t0n1zz commented Sep 29, 2018

so the solution is? manual build?

@kball
Copy link
Author

kball commented Oct 2, 2018

@t0n1zz I ended up pulling out vue-filters and manually copying the pieces we were using. So yeah, I think manual build...

I think it would be very quick to update to allow optional namespacing via an alternative import, but I'm hesitant to implement that unless the maintainer expresses any interest in that approach. (cc @freearhey)

@kball
Copy link
Author

kball commented Oct 4, 2018

FWIW @t0n1zz @erikverbeek @akhoury I have implemented a version of this and submitted it as a PR. Would be happy for feedback on better approaches, or if you want to install directly from a branch I can create one that includes a recompiled distfile

@t0n1zz
Copy link

t0n1zz commented Oct 5, 2018

@kball oh yea i would love to try it... i "must' need this package and on the other end i want to also adding select2 or something like that... to do search on select and multiple select but both of them just can't work together

jgsnat pushed a commit to jgsnat/vue2-filters that referenced this issue Oct 10, 2018
@jgsnat
Copy link

jgsnat commented Oct 10, 2018

I uploaded a change that I believe solves this problem. Now just wait to leave the new version

@freearhey freearhey added the bug label Nov 5, 2018
@kaiserkiwi
Copy link

Will this bug ever get fixed in a release version? The fix is now 27 days old but the last release version is from January.

@freearhey
Copy link
Owner

If you came across this bug please upgrade the package up to v0.4.0. In new version global mixins has been removed and errors must disappear.

Now in order to use methods such as limitBy, filterBy , find or orderBy , you need to register Vue2Filters.mixin in the component manually, like so:

import Vue2Filters from 'vue2-filters'

export default {
  ...
  mixins: [Vue2Filters.mixin],
  ...
}

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants