将 immutable.js 对象传递给 Ramda 函数不起作用 - 管道函数未被调用

Passing immutable.js object into Ramda functions does not work - pipe function is not called

我继承了使用immutable.js实现的redux store(store对象是Map)。

当我尝试 pipe 通过 ramda 存储时,它不起作用:

  import { pipe, tap } from 'ramda';

  it.only('should handle data loading', () => {
    const initialState = home(); // it returns map
    const fn = pipe(
      tap(x => {
        console.log('i am inside tap', x);
      })
    );
    console.log('this is initialState', initialState); // prints state to console correctly
    fn('wtf');          // works - tap is called
    fn(initialState);   // does not work - tap is not called
  });

你知道为什么 fn(initialState) 不起作用吗?

tap 似乎有问题。而且好像是最近几个版本才引入的。以下两个片段之间的唯一区别是第一个使用 Ramda 0.24 而第二个使用 Ramda 0.26.1。在这些之间的某个地方,tap 似乎已经坏了。虽然它适用于某些值,但不适用于 Immutable。

你可以 raise an issue 使用 Ramda 项目吗?

const {Map} = immutable
const {tap, pipe, map} = ramda
const square = n => n * n;
const home = () => new Map({foo: 1, bar: 2, baz: 3});

const fn = pipe(
  tap(console.log),
  map(square),
  tap(console.log),
);

const initialState = home();

fn(initialState);   // does not work - tap is not called
<script src="https://bundle.run/ramda@0.24.0"></script>
<script src="https://bundle.run/immutable@4.0.0-rc.12"></script>

const {Map} = immutable
const {tap, pipe, map} = ramda
const square = n => n * n;
const home = () => new Map({foo: 1, bar: 2, baz: 3});

const fn = pipe(
  tap(console.log),
  map(square),
  tap(console.log),
);

const initialState = home();

fn(initialState);   // does not work - tap is not called
<script src="https://bundle.run/ramda@0.26.1"></script>
<script src="https://bundle.run/immutable@4.0.0-rc.12"></script>