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

时间:2019-04-11 08:12:47

标签: immutable.js ramda.js

我继承了使用immutable.js实现的redux存储(存储对象是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)无法正常工作吗?

1 个答案:

答案 0 :(得分:1)

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>