Git Product home page Git Product logo

Comments (5)

SharpSeeEr avatar SharpSeeEr commented on May 30, 2024 1

Ahhh! I hadn't considered that aspect of the $ prefix. Removing the prefix would prevent you from having property names of invalid, errors, messages, pending, etc. I don't think I've ever had data property names that need to be validated with any of those names, but if you make that a requirement it's guaranteed someone will.

So for the Entry and Result types leaving those $ prefixes in place makes sense. For Rule though there aren't any additional properties so the $ could be removed there.

from vue-tiny-validate.

SharpSeeEr avatar SharpSeeEr commented on May 30, 2024 1

Sorry! Was editing my comment as you closed it.

from vue-tiny-validate.

anh-ld avatar anh-ld commented on May 30, 2024 1

No worries 😅. I do agree that the $ prefix in Rule need to be removed. And the$key should be renamed to name. 👍

from vue-tiny-validate.

anh-ld avatar anh-ld commented on May 30, 2024

Hi SharpSeeEr. Thank you for your suggestions.

The reason why I put the $ prefix in property names of Entry and Result is to differentiate these properties with data properties.

Lets take a look at the example below

const data = reactive({
    test: false,
    invalid: false
})

const rule = reactive({
    test: { $test: value => Boolean(value), $key: 'bool' },
    invalid: { $test: value => Boolean(value), $key: 'bool' },
})

const { result } = useValidate(data, rule)

And then the result object will be

{
    $invalid: false;
    $errors: [];
    $messages: [];
    $pending: false;
    $test: () => void;
    $reset: () => void;
    $touch: () => void;
    test: {
        $invalid: false;
        $errors: [];
        $messages: [];
        $pending: false;
        $test: () => void;
        $reset: () => void;
        $touch: () => void;
    },
    invalid: {
        $invalid: false;
        $errors: [];
        $messages: [];
        $pending: false;
        $test: () => void;
        $reset: () => void;
        $touch: () => void;
    }
}

As you can see, if I remove the $ prefix, the test method will be replace by the test property. That's not what I want.

Removing $ in the Rule is not a big deal. I'm ok with that thing. However, why I still keep it is because I want to keep property names pattern consistent between objects.

Currently, I haven't found any solution for this problem. So, any ideas?

from vue-tiny-validate.

anh-ld avatar anh-ld commented on May 30, 2024

Updated #6

from vue-tiny-validate.

Related Issues (8)

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.