为什么这不适用于 recompose 和 ramda?

Why this doesn't work with recompose and ramda?

在我的 hoc 中,我有这个条件;

   branch(R.propSatisfies(R.isEmpty, "repos"), renderComponent(Loader)),
// branch(R.isEmpty("repos"), renderComponent(Loader)),

有什么区别,为什么第二个给我一个错误? test is not a function

同样的结果:

branch(R.isEmpty(R.props("repos")), renderComponent(Loader)),

这是因为 R.propSatisfiesR.isEmpty 的方法签名不同。

对于第一种方法:

branch(R.propSatisfies(R.isEmpty, "repos"), renderComponent(Loader))

R.propSatisfies 函数正在对输入对象(即从 renderComponent(Loader)).

对于第二种方法:

// branch(R.isEmpty("repos"), renderComponent(Loader)),

您在这里所做的是直接调用 R.isEmptyR.isEmpty 方法需要一个数组,如果提供的数组为空,则 returns 为真。 R.isEmpty 无法确定对象中的 属性(即 "repos")是否为空。为了更容易想象这里发生了什么,请考虑以下内容:

// Your second approach:
branch(R.isEmpty("repos"), renderComponent(Loader))

// ...which when expanded, is equivalent to this. You can now see it 
// shows incorrect usage of R.isEmpty
branch(component => R.isEmpty("repos")(component), renderComponent(Loader))

希望这能提供一些说明 - 有关 R.isEmptysee this link

的更多信息

R. IsEmpty 是一元函数,它报告某个值是否为其类型(例如空字符串、空对象或空数组)的空值。当你用 "repos" 调用它时,你会得到 false 因为 "repos" 不是空字符串。据推测,您调用的 branch 函数需要一个谓词函数作为第一个参数,并且在您发送此布尔值时它失败了。类似地,由于 R. props (你可能意味着 R.prop 顺便说一句,但同样的问题也适用)是一个二元函数, R.props("repos") returns 一个函数,它不是空的,所以isEmpty returns 错误。

另一方面,

R.propSatisfies 是一个接受谓词函数、属性 名称和对象的三元函数。当你用 isEmpty"repos" 调用它时,你会得到一个等待对象的函数。它被传递给 branch,一切都很好。

您不喜欢 propSatisfies 版本的原因是什么?