我可以在 Javascript 中再次导入吗?
Can I import again in Javascript?
例如App.js
我有
let store = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
export { store }
当我在另一个文件中执行 import { store as mainStore } from './App'
时,我认为它会在变为 mainStore
之前变为 运行 createStore
。我可以重新导入,以便此代码稍后再次成为 运行 吗?对于这个例子,我确实想在测试之间重置 store
变量的状态。 createStore
方法可以做到这一点。
For this instance I do want to reset the store variable's state in
between tests. And the createStore method can do just that.
解决方案 1:
如果你想重置存储变量,那么在 redux 中你可以 dispatch action 并将特定存储值设置为你想要的任何值
方案二:怀疑满
创建不同的商店变量,例如
export const store1 = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
export const store2 = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
例如App.js
我有
let store = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
export { store }
当我在另一个文件中执行 import { store as mainStore } from './App'
时,我认为它会在变为 mainStore
之前变为 运行 createStore
。我可以重新导入,以便此代码稍后再次成为 运行 吗?对于这个例子,我确实想在测试之间重置 store
变量的状态。 createStore
方法可以做到这一点。
For this instance I do want to reset the store variable's state in between tests. And the createStore method can do just that.
解决方案 1:
如果你想重置存储变量,那么在 redux 中你可以 dispatch action 并将特定存储值设置为你想要的任何值
方案二:怀疑满
创建不同的商店变量,例如
export const store1 = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));
export const store2 = createStore(CombinedReducers, applyMiddleware(promiseMiddleware));