Immutable.js 在不可变 Map 中转换嵌套数组
Immutable.js turn nested array in immutable Map
我没有得到关于以下问题的解决方案。我希望这对其他一些开发人员有用。我正在尝试了解 Immutable.js。我正在编写一个测试和一个函数,但我没有得到想要的结果,我不明白我应该怎么做...
-> 我有嵌套数组成员
-> 我应该在下面的函数中放入什么来将测试数组变成不可变的嵌套映射?
-> 结果会怎样?
我有这个功能:
import {List, Map, fromJS} from 'immutable';
export function setInitial(state, infos, members) {
return state.set('infos', Map(infos))
.set('members', ?????(members));
}
...还有这个测试...
import {List, Map} from 'immutable';
import {expect} from 'chai';
import {setInitial,
addAtListOfMembers,
removeAtListOfMembers
} from '../src/core';
describe('application logic', () => {
describe('setInitial', () => {
it('charge the infos of the laboratory', () => {
const state = Map();
const infos = {
id:1,
laboName: 'Magenta Service',
phone: '+331650042958',
mail: 'email@magentaservice.fr',
date: '12/5/2014'
};
const members = [
{
id:1,
userName:'René',
date:'12/02/2016'
},
{
id:2,
userName:'Jean',
date:'10/03/2016'
}
];
const nextState = setInitial(state, infos, members);
expect(nextState).to.equal(Map({
infos : Map({
id:1,
laboName: 'Magenta Service',
phone: '+331650042958',
mail: 'email@magentaservice.fr',
date: '12/5/2014'
}),
// =>MAYBE ???
members: List.of(
Map({
id:1,
userName:'René',
date:'12/02/2016'
}),
Map({
id:2,
userName:'Jean',
date:'10/03/2016'
})
);
}));
});
});
});
预先感谢您的回答!
Immutable.fromJS()
随心所欲。
我没有得到关于以下问题的解决方案。我希望这对其他一些开发人员有用。我正在尝试了解 Immutable.js。我正在编写一个测试和一个函数,但我没有得到想要的结果,我不明白我应该怎么做...
-> 我有嵌套数组成员 -> 我应该在下面的函数中放入什么来将测试数组变成不可变的嵌套映射? -> 结果会怎样?
我有这个功能:
import {List, Map, fromJS} from 'immutable';
export function setInitial(state, infos, members) {
return state.set('infos', Map(infos))
.set('members', ?????(members));
}
...还有这个测试...
import {List, Map} from 'immutable';
import {expect} from 'chai';
import {setInitial,
addAtListOfMembers,
removeAtListOfMembers
} from '../src/core';
describe('application logic', () => {
describe('setInitial', () => {
it('charge the infos of the laboratory', () => {
const state = Map();
const infos = {
id:1,
laboName: 'Magenta Service',
phone: '+331650042958',
mail: 'email@magentaservice.fr',
date: '12/5/2014'
};
const members = [
{
id:1,
userName:'René',
date:'12/02/2016'
},
{
id:2,
userName:'Jean',
date:'10/03/2016'
}
];
const nextState = setInitial(state, infos, members);
expect(nextState).to.equal(Map({
infos : Map({
id:1,
laboName: 'Magenta Service',
phone: '+331650042958',
mail: 'email@magentaservice.fr',
date: '12/5/2014'
}),
// =>MAYBE ???
members: List.of(
Map({
id:1,
userName:'René',
date:'12/02/2016'
}),
Map({
id:2,
userName:'Jean',
date:'10/03/2016'
})
);
}));
});
});
});
预先感谢您的回答!
Immutable.fromJS()
随心所欲。