moved l-a-s in here
This commit is contained in:
parent
1e3e55e362
commit
836ab07776
18 changed files with 3946 additions and 281 deletions
|
|
@ -1,10 +1,11 @@
|
|||
const R = require('ramda')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
module.exports = {
|
||||
unscoped,
|
||||
cryptoScoped,
|
||||
machineScoped,
|
||||
scoped
|
||||
scoped,
|
||||
scopedValue
|
||||
}
|
||||
|
||||
function matchesValue (crypto, machine, instance) {
|
||||
|
|
@ -13,7 +14,7 @@ function matchesValue (crypto, machine, instance) {
|
|||
}
|
||||
|
||||
function permutations (crypto, machine) {
|
||||
return R.uniq([
|
||||
return _.uniq([
|
||||
[crypto, machine],
|
||||
[crypto, 'global'],
|
||||
['global', machine],
|
||||
|
|
@ -22,21 +23,26 @@ function permutations (crypto, machine) {
|
|||
}
|
||||
|
||||
function fallbackValue (crypto, machine, instances) {
|
||||
const notNil = R.pipe(R.isNil, R.not)
|
||||
const pickValue = arr => R.find(instance => matchesValue(arr[0], arr[1], instance), instances)
|
||||
const fallbackRec = R.find(notNil, R.map(pickValue, permutations(crypto, machine)))
|
||||
const notNil = _.negate(_.isNil)
|
||||
const pickValue = arr => _.find(instance => matchesValue(arr[0], arr[1], instance), instances)
|
||||
const fallbackRec = _.find(notNil, _.map(pickValue, permutations(crypto, machine)))
|
||||
return fallbackRec && fallbackRec.fieldValue.value
|
||||
}
|
||||
|
||||
function scopedValue (crypto, machine, fieldCode, config) {
|
||||
const allScopes = config.filter(_.pathEq(['fieldLocator', 'code'], fieldCode))
|
||||
|
||||
return fallbackValue(crypto, machine, allScopes)
|
||||
}
|
||||
|
||||
function generalScoped (crypto, machine, config) {
|
||||
const scopedValue = (key, instances) =>
|
||||
fallbackValue(crypto, machine, instances)
|
||||
const localScopedValue = key =>
|
||||
scopedValue(crypto, machine, key, config)
|
||||
|
||||
const allScopes = key => config.filter(R.pathEq(['fieldLocator', 'code'], key))
|
||||
const keys = R.uniq(R.map(r => r.fieldLocator.code, config))
|
||||
const keyedValues = keys.map(key => scopedValue(key, allScopes(key)))
|
||||
const keys = _.uniq(_.map(r => r.fieldLocator.code, config))
|
||||
const keyedValues = keys.map(localScopedValue)
|
||||
|
||||
return R.zipObj(keys, keyedValues)
|
||||
return _.zipObject(keys, keyedValues)
|
||||
}
|
||||
|
||||
function machineScoped (machine, config) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue