Skip to content

Conversation

@delvedor
Copy link
Member

As titled.
Thanks to this symbol, other libraries that accept validation objects, can directly accept fluent schema objects and call .valueOf internally.
This vastly improves the user experience and hides one of the most common mistakes that devs make with this library.

const S = require('fluent-schema')

const schema = S.object()
  .prop('foo', S.string())
  .prop('bar', S.number())

console.log(schema[Symbol.for('fluent-schema-object')]) // true

Once this pr is merged and released, I'll open a pr to Fastify to support this new feature.

@delvedor delvedor requested review from aboutlo and mcollina June 20, 2019 12:57
@aboutlo
Copy link
Collaborator

aboutlo commented Jun 20, 2019

Nice, I will look into ASAP

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aboutlo
Copy link
Collaborator

aboutlo commented Jun 20, 2019

Thank you @delvedor!
This approach is nicer in order to understand if the object is a FluntSchema. Could be used here as well: https://github.com/fastify/fluent-schema/blob/0cb9d8999d8bbe502047857feca91014a8253ccc/src/utils.js#L2-L2

Apert that I'm fine to merge it, just let me know if you can change isFluentSchema as well.

@delvedor
Copy link
Member Author

Good point @aboutlo, done!

@aboutlo aboutlo merged commit 5382d9b into master Jun 22, 2019
@delvedor delvedor deleted the symbol branch June 24, 2019 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants