Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Jul 18, 2016
1 parent 3293251 commit dbf3d9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
28 changes: 27 additions & 1 deletion lib/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ exports.__esModule = true;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _typeName = require('type-name');

var _typeName2 = _interopRequireDefault(_typeName);

var _inherits = require('./util/inherits');

var _inherits2 = _interopRequireDefault(_inherits);
Expand All @@ -12,6 +16,10 @@ var _isAbsent = require('./util/isAbsent');

var _isAbsent2 = _interopRequireDefault(_isAbsent);

var _isSchema = require('./util/isSchema');

var _isSchema2 = _interopRequireDefault(_isSchema);

var _mixed = require('./mixed');

var _mixed2 = _interopRequireDefault(_mixed);
Expand All @@ -38,7 +46,9 @@ function ArraySchema(type) {

_mixed2.default.call(this, { type: 'array' });

this._subType = null;
// `undefined` specifically means uninitialized, as opposed to
// "no subtype"
this._subType = undefined;

this.withMutation(function () {
_this.transform(function (values) {
Expand Down Expand Up @@ -112,9 +122,25 @@ function ArraySchema(type) {
});
});
},


// concat(schema) {
// var next = MixedSchema.prototype.concat.call(this, schema)
//
// next._subType = schema._subType === undefined
// ? this._subType
// : schema._subType;
//
// return next
// },

of: function of(schema) {
var next = this.clone();

if (schema !== false && !(0, _isSchema2.default)(schema)) throw new TypeError('`array.of()` sub-schema must be a valid yup schema, or `false` to negate a current sub-schema. ' + 'got: ' + (0, _typeName2.default)(schema) + ' instead');

next._subType = schema;

return next;
},
required: function required(msg) {
Expand Down
11 changes: 8 additions & 3 deletions lib/util/reach.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ module.exports = function (obj, path, value, context) {
var part = isBracket ? trim(_part) : _part;

if (isArray || (0, _has2.default)(obj, '_subType')) {
// we skipped an array
// we skipped an array: foo[].bar
var idx = isArray ? parseInt(part, 10) : 0;

obj = obj.resolve({ context: context, parent: parent, value: value })._subType;

if (value) {

if (isArray && idx >= value.length) {
throw new Error('Yup.reach cannot resolve an array item at index: ' + _part + ', in the path: ' + path + '. ' + 'because there is no value at that index. ');
}

value = value[idx];
}
}
Expand All @@ -49,5 +50,9 @@ module.exports = function (obj, path, value, context) {
}
});

return obj && obj.resolve({ context: context, parent: parent, value: value });
if (obj) {
obj = obj.resolve({ context: context, parent: parent, value: value });
}

return obj;
};

0 comments on commit dbf3d9f

Please sign in to comment.