start refactoring#2
Conversation
|
@doowb, any thoughts on how to handle this case (where var Schema = require('..');
var foo = new Schema()
.field('a', {default: 'aaa'})
.field('b', {default: 'bbb'})
.field('c', {default: 'ccc'})
var config = {foo: 'bar'};
var schema = new Schema()
.field('foo', foo)
.normalize(config)
console.log(config)Currently (in the refactor), when nested schemas are used, the value of var Schema = require('..');
var foo = new Schema()
.field('a', {default: 'aaa'})
.field('b', {default: 'bbb'})
.field('c', {default: 'ccc'})
var config = {foo: 'bar'};
var schema = new Schema()
.field('foo', {
normalize: function(val, key, config, schema) {
// decide what to do with val if not an object, or...
return foo.normalize.apply(foo, arguments);
}
})
.normalize(config)
console.log(config)edit: I think I have a better solution. If a var foo = new Schema({
normalize: function() {
// do stuff
}})
.field('a', {default: 'aaa'})
.field('b', {default: 'bbb'})
.field('c', {default: 'ccc'}) |
Yeah, I think this is how I envisioned it. Like if "foo" was "author" in a package.json and the "author" field was a string, but there was an "author" schema specified for it, that schema could transform the string into an object. |
yeah, it would have worked that way already. but this way it would also have the option of returning the string unchanged. |
|
Yeah, I think that makes sense |
cc @doowb