add customizer for merging arrays

This commit is contained in:
akirilyuk
2022-02-04 08:21:53 +01:00
parent 2a61d21bff
commit 50f926bce4

View File

@@ -1,4 +1,6 @@
const obj = require('drachtio-fsmrf/lib/utils');
const Emitter = require('events'); const Emitter = require('events');
const { isArray } = require('lodash');
const lodash = require('lodash'); const lodash = require('lodash');
const hasKeys = (obj) => typeof obj === 'object' && Object.keys(obj) > 0; const hasKeys = (obj) => typeof obj === 'object' && Object.keys(obj) > 0;
@@ -18,11 +20,17 @@ class SpeechConfig extends Emitter {
_mergeConfig(changedConfig = {}) { _mergeConfig(changedConfig = {}) {
const merged = lodash.merge( const merged = lodash.merge(
{},
this.sessionConfig, this.sessionConfig,
changedConfig changedConfig,
(objValue, sourceValue) => {
if(isArray(objValue)){
if(isArray(sourceValue)){
return sourceValue;
}
return objValue;
}
}
); );
merged.bargein.enable = changedConfig.bargein?.enable?.length === 0 ? [] : changedConfig.bargein?.enable;
this.logger.debug({merged, sessionConfig: this.sessionConfig, changedConfig}, 'merged config'); this.logger.debug({merged, sessionConfig: this.sessionConfig, changedConfig}, 'merged config');
// should we override hints with empty array or leave it as it is once saved? // should we override hints with empty array or leave it as it is once saved?
// merged.recognizer.hints = changedConfig.recognizer?.hints // merged.recognizer.hints = changedConfig.recognizer?.hints