From 6d8e4904dc7a111d9311ecd52ef5f973215bcacc Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 17 Oct 2016 16:21:23 -0700 Subject: [PATCH 1/2] Update Schema.js Call `fieldArrayCalcLength` with `this` object --- src/Schema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Schema.js b/src/Schema.js index 49a2758..dda85a2 100644 --- a/src/Schema.js +++ b/src/Schema.js @@ -68,7 +68,7 @@ export default class Schema extends Generator{ na = (fieldConfig.concatStrict) ? [...new Set(na)] : na } - let length = fieldArrayCalcLength(fieldConfig, na.length) + let length = fieldArrayCalcLength(fieldConfig, na.length, this) Array.from(new Array(length)).map(() => { array.push(this.generateField(fieldConfig)) From e87a7596a52a0f64bd5db4d04cda0b7825ff6147 Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 17 Oct 2016 16:21:51 -0700 Subject: [PATCH 2/2] Update utils.js Check for `length` as a function. --- src/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/utils.js b/src/utils.js index e8607cd..afbbbcf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,9 +11,11 @@ export const evalWithContextData = function (key, object, db) { return eval(key) } -export const fieldArrayCalcLength = function (config, fixedArrayLength) { +export const fieldArrayCalcLength = function (config, fixedArrayLength, schema) { let length - if (config.fixedLength) { + if (typeof config.length === 'function') { + length = config.length.call(schema); + } else if (config.fixedLength) { length = config.length - fixedArrayLength } else { length = Math.floor((Math.random() * config.length) + 1)