ES6模块初始化顺序错误
ES6 modules initializing the wrong order?
所以我有一个模块树,特别是两个表现异常的模块。使用Babel 6+Browserify(babelify)。
模块#1(WindowManager/index.js)导出一个名为reducer
的命名函数,以及一个默认导出。
import WindowManager from './component';
import { combineReducers } from 'redux';
import { connect } from 'react-redux';
import { reducer as search_palette } from './SearchPalette';
const initialState = {
// stuff
};
const window_manager = (state = initialState, action) => {
// stuff
return state;
};
export const reducer = combineReducers({window_manager, search_palette})
const mapStateToProps = (state) => {
return {
// stuff
};
};
export default connect(mapStateToProps)(WindowManager)
模块#2(store.js)导入WindowManager/index.js
的reducer
函数并尝试使用它
import { createStore, combineReducers } from 'redux';
import { reducer as WindowManagerReducer } from './WindowManager';
const initialState = {
// stuff
};
const FetchApplicationsReducer = (state = initialState, action) => {
// stuff
return state;
}
export default createStore(
combineReducers({
applications: FetchApplicationsReducer,
ui: WindowManagerReducer,
})
)
由于某种原因,store.js在WindowManager/index.js
之前执行,因此导出不可用。
有人碰到这个吗?
经过多次调整,修改import
语句的顺序解决了这个问题。这是一棵复杂的树,很难在这里以一种不涉及整个项目的方式来表示。。。但我认为最终Babel的ES6模块系统中可能存在漏洞。
相关文章:
- Javascript执行顺序错误
- 按 [field] 值对 javascript 数组进行排序会给出错误的顺序
- 带有 CommonsChunkPlugin 的 Webpack 会导致 html 文件中的捆绑顺序错误
- For循环以错误的顺序返回promise
- Javascript错误的警报顺序
- three.js:透明对象根据相机角度按错误顺序渲染
- ES6模块初始化顺序错误
- 在Firefox中的keydown事件中隐藏元素时焦点顺序错误
- 使用 JS 填充 HTML 表,数据顺序错误
- JavaScript 排序顺序错误
- Angular + Requirejs - 以错误的顺序加载
- Mixpanel javascript 集成:连续的事件在 mixpanel 结束时以错误的顺序记录
- 视图中的 JavaScript 错误 - 加载顺序
- ReactJS:Dom 渲染顺序错误
- JQuery 错误的脚本顺序
- AngularJS$q承诺成功的回调以错误的顺序执行
- Angular orderBy:“timestamp”将事物按错误的顺序排列
- kafka节点的消息顺序错误
- 在IE8和IE7(Telerik radgrid)中以错误的顺序触发javascript事件
- angularjs ng repeat中的错误顺序