Skip to content

Commit

Permalink
feat: deprecate the getter overload of default()
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Nov 19, 2020
1 parent e77574c commit b7fbe67
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/mixed.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,29 @@ const proto = (SchemaType.prototype = {
}
},

_getDefault() {
var defaultValue = has(this, '_default')
? this._default
: this._defaultDefault;

return typeof defaultValue === 'function'
? defaultValue.call(this)
: cloneDeepWith(defaultValue);
},

getDefault(options = {}) {
let schema = this.resolve(options);
return schema.default();
return schema._getDefault();
},

default(def) {
if (arguments.length === 0) {
var defaultValue = has(this, '_default')
? this._default
: this._defaultDefault;
console.warn(
'Calling `schema.default()` as a getter to retrieve a default is deprecated and will be removed in the next version. \n' +
'Use `schema.getDefault()` instead.',
);

return typeof defaultValue === 'function'
? defaultValue.call(this)
: cloneDeepWith(defaultValue);
return this._getDefault();
}

var next = this.clone();
Expand Down

0 comments on commit b7fbe67

Please sign in to comment.