Git Product home page Git Product logo

Comments (5)

ealush avatar ealush commented on May 26, 2024 1

I am afraid it might be confusing with the behavior of skip, which works within the current scope, while optional works on the suite level. Essentially, at any nesting level where you put skip, it only applies to the descendants of that scope. A consumer of vest could mistake omit() to work just like this.

I am wondering if this is more reasonable to create a general-case omit() that would be similar to the way skip currently works.

from vest.

ealush avatar ealush commented on May 26, 2024

I think that what you're after is optional with custom rules. Optional has two modes - one that only takes the field name. That's the default behavior, and one that takes a boolean/function value that describes whether the field should be omitted.

optional({
  username: true // Will be omitted
});

The only difference between this and omitWhen is that optional runs on a second pass, meaning - it runs the field normally, but then excludes it. I can imagine it useful that if the optional condition is set from the get-go and not a function, it will behave the same as your imagined omit. That's especially true for async validations

from vest.

vonagam avatar vonagam commented on May 26, 2024

Oh, cool, I saw optional but it was documented mostly in the context of a value missing (event custom functions were kinda about that) and there was no example with booleans. Seem to be working, thanks.

from vest.

ealush avatar ealush commented on May 26, 2024

Scratch My latest comment about the difference with what you're after. Just looked at the code, it behaves just as you'd expect. Wrote a few new tests to confirm that.

287f65e

from vest.

vonagam avatar vonagam commented on May 26, 2024

Hm... so why not introduce omit as an alias for optional of sorts?

To omit with optional I would need to reduce an array into an object and then vest will iterate over that object to make SuiteOptionalFields.setOptionalField (where third argument can be reused for all omitted, as they have no custom logic or need for checks). So it would be both more convenient and more performant to allow passing an array directly.

omit(["asd"]) as optional({"asd": true}). (Just a thought, not a request.)

from vest.

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.