下面的代码片段出现在
http://www.jchapron.com/2015/08/14/getting-started-with-redux/
import React from 'react';
import { createStore as initialCreateStore, compose } from 'redux';
export let createStore = initialCreateStore;
if (__DEV__) {
createStore = compose(
require('redux-devtools').devTools(),
require('redux-devtools').persistState(
window.location.href.match(/[?&]debug_session=([^&]+)\b/)
),
createStore
);为什么作者将initialCreateStore导入为createStore,然后将相同的结果重新分配给createStore
从一开始就会导入createStore做同样的事情吗?
发布于 2015-11-27 12:31:23
为什么作者将
initialCreateStore导入为createStore?
他不知道,情况正好相反。import正在模块作用域中创建initialCreateStore绑定。
为什么他会将同样的结果重新分配给
createStore呢?
因为你的唠叨。他想要明确地指出,它只是导出绑定的初始值。
从一开始就会导入
createStore做同样的事情吗?
不是,因为在ES6中导入的绑定是“不可变的”--它们可以更改(如果它们在导出它们的模块中更改),但是它们不能分配到导入模块中。
但是,作者确实希望用自己的createStore覆盖__DEV__,因此他确实需要声明自己与export let createStore的绑定。
https://stackoverflow.com/questions/33957341
复制相似问题