我继承了使用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)
无法正常工作吗?
答案 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>