GithubHelp home page GithubHelp logo

Validation is synchronous about jugglingdb HOT 6 CLOSED

1602 avatar 1602 commented on August 18, 2024
Validation is synchronous

from jugglingdb.

Comments (6)

juggy avatar juggy commented on August 18, 2024

To complement on that, here is the error so you can understand the problem:

TypeError: Object false has no method 'add'
at onerror (/Users/juggy/Documents/jugglingdb/lib/validatable.js:167:21)
at [object Object].<anonymous> (/Users/juggy/Documents/jugglingdb/lib/validatable.js:88:17)
at native
at /Users/juggy/Documents/jugglingdb/lib/abstract-class.js:182:13
at Array.<anonymous> (/Users/juggy/Documents/jugglingdb/lib/adapters/memory.js:49:9)
at EventEmitter._tickCallback (node.js:126:26)

When trying to add the error, the attribute errors is not an error array anymore but a boolean false.

from jugglingdb.

1602 avatar 1602 commented on August 18, 2024

Yeah, got it. You get this errors because sync validation has been done, and normal flow was continued. The root of problem in syncronous validations nature (async validations missed at the moment).

Of course async validations should be implemented too. But I want to implement it degraded gracefully: when no async validations set up isValid will return correct value, depends on instance state. But when one or more async validations was set up isValid will always return false and it should accept one param (callback) which will be called with validation result.

Second way of using isValid method shall work for both cases (sync and async), and first way shall only work for sync validations. The reason why I want to support two ways of using it is to keep sync code as simple as possible when no async validations needed.

But I'm open to any other ideas. And maybe better to swith fully to async validations, don't really sure. Please, share your thoughts on this.

Thanks.

from jugglingdb.

juggy avatar juggy commented on August 18, 2024

Implementing both type would add complexity to the code I think. The only way i really see using async validation everywhere. The question is really how to implement it so it is still not too heavy.

from jugglingdb.

1602 avatar 1602 commented on August 18, 2024

I've just implemented validations in async way. Sync way still works. Also implemented (quick and dirty) new async validation validatesUniquenessOf, check tests. Feel free to fork and improve it, or suggest any fixes if you found any new bugs related to async validations.

As you can see in tests custom async validation (called validateAsync) shoul declare callback which accepts two callbacks, first one for error (should be called with error label each time when error spotted), and second - done - should be called when async validation completed.

from jugglingdb.

juggy avatar juggy commented on August 18, 2024

Thanks. It looks good I will try it this evening. It's getting somewhere! :)

from jugglingdb.

juggy avatar juggy commented on August 18, 2024

The latest changes for the async validation are working for me.

from jugglingdb.

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.