Giter Club home page Giter Club logo

Comments (5)

tmpfs avatar tmpfs commented on June 16, 2024

Thanks for the issue.

You can of course define a custom rule that would do this for your purpose, let's work together to find the best way to implement this for your use-case.

I am resting until the 10th, I'll be in touch again afterwards.

FYI:

Related: when defining an array of objects, is there a way to define the type of the items inside the arrays? I.e: type=array + items="Object", or in the above example type=array + items=[Person,Organization] might make sense for instance

Should be resolved with:

#46
6db76c4

You should be able to find a test case for this - let me know if there isn't one!

from async-validate.

tmpfs avatar tmpfs commented on June 16, 2024

Here is my current thinking, we define a rule property such as resolve which points to a function that inspects the object being processed and returns the rule to execute for that object. The function would be called synchronously and must return a valid rule, for example:

var Person = // define rule for person
var MusicGroup = // define rule for music group
function resolve() {
  switch(this['@type']) {  // called with `this` as the object being validated
    case "Person":
      return Person;
    case "MusicGroup":
      return MusicGroup;
  }
  throw new Error('Unknown @type encountered')
}

Then in the rule declaration assign the resolve() function to the resolve property which would be executed to locate the rule.

How does that sound?

from async-validate.

0xgeert avatar 0xgeert commented on June 16, 2024

Yep sounds good to me.

FYI: moved on by doing some custom hacking in schema.js that let's me
circumvent the issue since I needed some other stuff as well, but this
certainly seems to solve this particular issue pretty elegantly.

On Fri, Jan 8, 2016 at 12:00 PM, muji [email protected] wrote:

Here is my current thinking, we define a rule property such as resolve
which points to a function that inspects the object being processed and
returns the rule to execute for that object. The function would be called
synchronously and must return a valid rule, for example:

var Person = // define rule for personvar MusicGroup = // define rule for music groupfunction resolve() {
switch(this['@type']) { // called with this as the object being validated
case "Person":
return Person;
case "MusicGroup":
return MusicGroup;
}
throw new Error('Unknown @type encountered')
}

Then in the rule declaration assign the resolve() function to the resolve
property which would be executed to locate the rule.

How does that sound?


Reply to this email directly or view it on GitHub
#56 (comment)
.

from async-validate.

tmpfs avatar tmpfs commented on June 16, 2024

This has been implemented in ef53cae.

Added to the readme here:

https://github.com/tmpfs/async-validate#resolve

Test spec is here:

https://github.com/tmpfs/async-validate/blob/master/test/spec/resolve.js

Published to the registry as 0.12.4.

I have found a bug noted here #57 which may or may not be related to the resolve implementation, I have a feeling this is a wider issue to do with handling arrays at the top-level, will investigate later.

For the moment I am closing this particular issue as implemented - hope it helps!

from async-validate.

0xgeert avatar 0xgeert commented on June 16, 2024

cheers!

On Tue, Jan 12, 2016 at 7:02 AM, muji [email protected] wrote:

Closed #56 #56.


Reply to this email directly or view it on GitHub
#56 (comment).

from async-validate.

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.