mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
adding a redux todo list to playground
This commit is contained in:
22
playground/src/reducers/index.ts
Normal file
22
playground/src/reducers/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { createReducer } from './createReducer';
|
||||
import { Store, FilterTypes } from '../store';
|
||||
import { combineReducers } from 'redux';
|
||||
|
||||
let counter = 0;
|
||||
|
||||
export const reducer = combineReducers<Store>({
|
||||
todos: createReducer(
|
||||
{},
|
||||
{
|
||||
add(state, action) {
|
||||
const id = String(counter++);
|
||||
return { ...state, [id]: { label: action.label, completed: false } };
|
||||
}
|
||||
}
|
||||
),
|
||||
filter: createReducer<FilterTypes>('all', {
|
||||
filter(state, action) {
|
||||
return action.filter;
|
||||
}
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user