希望使用ramda,我想对配置进行更改,并使用它们更新用户配置,其中属性/ ies更改具有相同的旧值。
经过讨论。变化。我将保留一个更改对象,只有R.merge(原始,用户)。但是,我需要能够提取已更改的属性及其值,以便在用户配置时我可以将该对象合并到用户中。
示例:
var original = { name:'test', setting1:1, setting2:2 };
var toChange = R.clone(original);
var userConfig {};
/// edit toChange
toChange.setting1 = 2;
/// extract setting1 and value from toChange
R.difference(original,toChange) => should be { setting1:2 };
/// but this does not work, no matter what way round i put original
/// and toChange, need to extract that change / diff
/// so i can then
userConfig = R.merge(userConfig, R.difference(original,toChange)); // for example

答案 0 :(得分:0)
找到一种方法来解决某人想要做同样的事情
var orig = {a: 1, b: 2, c: 3};
var edited = R.merge(R.clone(orig),{b:7});
var user = { d: 4 };
//check if left value == right value
//if not, return null
//on merge with
//wrap around reject if null
//wrap around a merge into user
user = R.merge(user, R.reject(R.isNil,
R.mergeWith(function(l,r){
return (R.equals(l,r)) ? null : l;
},edited,orig)));
console.log(user);

<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.24.1/ramda.min.js"></script>
&#13;