【发布时间】:2018-01-30 15:12:16
【问题描述】:
我有 redux store 和 object key value 对,如下所示:
{
"appElements": {
"layers": {
"layer_1": {
"scene": {
"width": "100px",
"height": "100px",
"bgColor": "#aaaaaa",
"bgImage": "http:bgimage1.png"
},
"items": {
"yrgroih9": {
"width": "100px",
"x": "200px"
},
"qhy0dukj": {
"width": "100px",
"x": "200px"
},
"7lw2nvma": {
"width": "100px",
"x": "200px"
}
}
}
}
}
}
我正在使用Immutable Js并将上述数据存储为不可变的Map数据类型到存储中。
我需要将上面给出的存储值保存到外部json文件中,例如mysavedfile.json。
react reducer 中使用的代码:
import { Map, fromJS, isImmutable } from 'immutable';
export default function images(state = new Map(), action) {
switch (action.type) {
case 'ADD_LAYERS':
return fromJS({ appElements:action.data.appElements });
case 'STATE_TO_JSON_FILE':
console.log("state");
//Here i need to do code to save state to external json file.
default:
return state
}
}
如何实现这个..?
【问题讨论】:
标签: json reactjs object react-redux immutable.js