Giter Site home page Giter Site logo

Comments (3)

thecodrr avatar thecodrr commented on June 6, 2024 1

Okay, I knew this would occur sooner or later.

We have two options here:

  1. We change the API to treat multi-filters as AND conditional (not as OR).
  2. We add a second parameter to the .filter method that defines whether it is AND or OR.

Which one makes the most sense? Should filters be, by default, AND conditioned?

from fdir.

kwaping avatar kwaping commented on June 6, 2024 1

I am not excited about breaking the existing API, but I think it's the right thing to do. The reason is that chained .filter calls in vanilla Javascript act in a cascading AND manner. You take the list, filter it, return the new list - then take that new list, filter it, return it - etc.

Besides this being what I would consider the expected behavior, there's also a lot less that can go wrong with this method. With the OR default, you can accidentally select more than you wanted - potentially a LOT more, causing speed and resource issues with your program. With the AND method, you might accidentally select too little, but that would have much less of a negative impact on your program.

I did work around the issue by just grabbing all the files and applying the cascading filters to the resulting array. The workaround for the current method would be to use pipes in a regex match. In terms of workarounds, leaving it as-is is superior. In that case, if you switch to AND by default, I suggest you add a flag for enabling OR mode.

EDIT: I forgot to add - thank you for your quick response and for this excellent piece of software!

from fdir.

thecodrr avatar thecodrr commented on June 6, 2024

I am not excited about breaking the existing API, but I think it's the right thing to do. The reason is that chained .filter calls in vanilla Javascript act in a cascading AND manner. You take the list, filter it, return the new list - then take that new list, filter it, return it - etc.

Yes but the filter of fdir works a little bit differently; it collects all the filters and then applies them all via filters.some. Since, there's no cascading, does it still make sense?

This line handles most of it:
if (filters.some((f) => f(filename))) files.push(filename);

To change it, all that has to be done is to swap .some with .every, I suppose.

In effect, this is just a convenient wrapper. You could easily just use a single .filter and put all the conditions in one (it might even be slightly more performant).

In terms of workarounds, leaving it as-is is superior. In that case, if you switch to AND by default, I suggest you add a flag for enabling OR mode.

I suppose we can add an option to toggle OR/AND mode.

I forgot to add - thank you for your quick response and for this excellent piece of software!

No problem, glad to have helped.

from fdir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.