Javascript 为什么在控制台中运行dispatch方法时,我的action creator返回ReferenceError消息?
我试图通过在控制台(Chrome developer tools)中使用Javascript 为什么在控制台中运行dispatch方法时,我的action creator返回ReferenceError消息?,javascript,redux,Javascript,Redux,我试图通过在控制台(Chrome developer tools)中使用store来测试我的动作创建者,但我一直收到这样的错误消息:Uncaught ReferenceError:receiveTodo未定义 我已经仔细检查了我的拼写/拼写错误,并导出了正确的模块,但我似乎仍然找不到我的错误所在 todo_actions.js export const RECEIVE_TODOS = "RECEIVE_TODOS"; export const RECEIVE_TODO = "RECEIVE_TO
store
来测试我的动作创建者,但我一直收到这样的错误消息:Uncaught ReferenceError:receiveTodo未定义
我已经仔细检查了我的拼写/拼写错误,并导出了正确的模块,但我似乎仍然找不到我的错误所在
todo_actions.js
export const RECEIVE_TODOS = "RECEIVE_TODOS";
export const RECEIVE_TODO = "RECEIVE_TODO";
export const receiveTodos = todos => ({
type: RECEIVE_TODOS,
todos
});
export const receiveTodo = todo => ({
type: RECEIVE_TODO,
todo
});
import { combineReducers } from 'redux';
import todosReducer from './todos_reducer';
const rootReducer = combineReducers({
todos: todosReducer
});
export default rootReducer;
import { RECEIVE_TODOS, RECEIVE_TODO } from '../actions/todo_actions';
// reducers/todos_reducer.js
const initialState = {
1: {
id: 1,
title: "wash car",
body: "with soap",
done: false
},
2: {
id: 2,
title: "wash dog",
body: "with shampoo",
done: true
}
};
const todosReducer = (state = initialState, action) => {
Object.freeze(state);
let nextState = {};
switch (action.type) {
case RECEIVE_TODOS:
action.todos.forEach(todo => nextState[todo.id] = todo);
return nextState;
case RECEIVE_TODO:
const newTodo = { [action.todo.id]: action.todo };
return Object.assign({}, state, newTodo);
default:
return state;
}
};
export default todosReducer;
import { createStore } from 'redux';
import rootReducer from '../reducers/root_reducer';
const configureStore = () => {
const store = createStore(rootReducer);
return store;
}
export default configureStore;
root_reducer.js
export const RECEIVE_TODOS = "RECEIVE_TODOS";
export const RECEIVE_TODO = "RECEIVE_TODO";
export const receiveTodos = todos => ({
type: RECEIVE_TODOS,
todos
});
export const receiveTodo = todo => ({
type: RECEIVE_TODO,
todo
});
import { combineReducers } from 'redux';
import todosReducer from './todos_reducer';
const rootReducer = combineReducers({
todos: todosReducer
});
export default rootReducer;
import { RECEIVE_TODOS, RECEIVE_TODO } from '../actions/todo_actions';
// reducers/todos_reducer.js
const initialState = {
1: {
id: 1,
title: "wash car",
body: "with soap",
done: false
},
2: {
id: 2,
title: "wash dog",
body: "with shampoo",
done: true
}
};
const todosReducer = (state = initialState, action) => {
Object.freeze(state);
let nextState = {};
switch (action.type) {
case RECEIVE_TODOS:
action.todos.forEach(todo => nextState[todo.id] = todo);
return nextState;
case RECEIVE_TODO:
const newTodo = { [action.todo.id]: action.todo };
return Object.assign({}, state, newTodo);
default:
return state;
}
};
export default todosReducer;
import { createStore } from 'redux';
import rootReducer from '../reducers/root_reducer';
const configureStore = () => {
const store = createStore(rootReducer);
return store;
}
export default configureStore;
todos_reducer.js
export const RECEIVE_TODOS = "RECEIVE_TODOS";
export const RECEIVE_TODO = "RECEIVE_TODO";
export const receiveTodos = todos => ({
type: RECEIVE_TODOS,
todos
});
export const receiveTodo = todo => ({
type: RECEIVE_TODO,
todo
});
import { combineReducers } from 'redux';
import todosReducer from './todos_reducer';
const rootReducer = combineReducers({
todos: todosReducer
});
export default rootReducer;
import { RECEIVE_TODOS, RECEIVE_TODO } from '../actions/todo_actions';
// reducers/todos_reducer.js
const initialState = {
1: {
id: 1,
title: "wash car",
body: "with soap",
done: false
},
2: {
id: 2,
title: "wash dog",
body: "with shampoo",
done: true
}
};
const todosReducer = (state = initialState, action) => {
Object.freeze(state);
let nextState = {};
switch (action.type) {
case RECEIVE_TODOS:
action.todos.forEach(todo => nextState[todo.id] = todo);
return nextState;
case RECEIVE_TODO:
const newTodo = { [action.todo.id]: action.todo };
return Object.assign({}, state, newTodo);
default:
return state;
}
};
export default todosReducer;
import { createStore } from 'redux';
import rootReducer from '../reducers/root_reducer';
const configureStore = () => {
const store = createStore(rootReducer);
return store;
}
export default configureStore;
store.js
export const RECEIVE_TODOS = "RECEIVE_TODOS";
export const RECEIVE_TODO = "RECEIVE_TODO";
export const receiveTodos = todos => ({
type: RECEIVE_TODOS,
todos
});
export const receiveTodo = todo => ({
type: RECEIVE_TODO,
todo
});
import { combineReducers } from 'redux';
import todosReducer from './todos_reducer';
const rootReducer = combineReducers({
todos: todosReducer
});
export default rootReducer;
import { RECEIVE_TODOS, RECEIVE_TODO } from '../actions/todo_actions';
// reducers/todos_reducer.js
const initialState = {
1: {
id: 1,
title: "wash car",
body: "with soap",
done: false
},
2: {
id: 2,
title: "wash dog",
body: "with shampoo",
done: true
}
};
const todosReducer = (state = initialState, action) => {
Object.freeze(state);
let nextState = {};
switch (action.type) {
case RECEIVE_TODOS:
action.todos.forEach(todo => nextState[todo.id] = todo);
return nextState;
case RECEIVE_TODO:
const newTodo = { [action.todo.id]: action.todo };
return Object.assign({}, state, newTodo);
default:
return state;
}
};
export default todosReducer;
import { createStore } from 'redux';
import rootReducer from '../reducers/root_reducer';
const configureStore = () => {
const store = createStore(rootReducer);
return store;
}
export default configureStore;
todo\u redux.jsx(我的输入文件)
从“React”导入React;
从“react dom”导入react dom;
从“./store/store”导入配置存储;
const store=configureStore();
window.store=商店;
常量根=()=>{
返回(
待办事项应用程序
);
}
document.addEventListener(“DOMContentLoaded”,()=>{
const root=document.getElementById('content');
ReactDOM.render(,root);
});
窗口上是否也有receiveTodo?我只看到那家店。啊,等等!就这样!非常感谢。出于好奇,我理解为什么我需要将其包含在窗口中进行测试,但我真的需要稍后在我的输入文件中导入这些动作创建者吗?Windows上是否也有receiveTodo?我只看到那家店。啊,等等!就这样!非常感谢。出于好奇,我理解为什么我需要将其包含在窗口中进行测试,但我真的需要稍后在我的输入文件中导入这些动作创建者吗??