mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-07-13 15:28:32 +08:00
removing docs from master branch
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
import { Store } from '../store';
|
||||
import { addTodo, remove, complete } from './pureFunctions';
|
||||
|
||||
export function reducer(state: Store['todos'], payload: any): Store['todos'] {
|
||||
switch (payload.type) {
|
||||
case 'addTodo':
|
||||
return addTodo(state, payload.id, payload.label);
|
||||
|
||||
// Fill in the blanks here for:
|
||||
// - remove
|
||||
// - complete
|
||||
// - clear
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { addTodo } from './pureFunctions';
|
||||
import { Store } from '../store';
|
||||
|
||||
describe('TodoApp reducers', () => {
|
||||
it('can add an item', () => {
|
||||
const state = <Store['todos']>{};
|
||||
|
||||
const newState = addTodo(state, '0', 'item1');
|
||||
|
||||
const keys = Object.keys(newState);
|
||||
|
||||
// make sure that adding an item would not result in the same instance of state
|
||||
// TODO: uncomment the below to get started
|
||||
/*
|
||||
|
||||
expect(newState).not.toBe(state);
|
||||
|
||||
expect(keys.length).toBe(1);
|
||||
expect(newState[keys[0]].label).toBe('item1');
|
||||
expect(newState[keys[0]].completed).toBeFalsy();
|
||||
*/
|
||||
});
|
||||
|
||||
// TODO: test remove, complete and clear
|
||||
});
|
||||
@@ -1,38 +0,0 @@
|
||||
import { Store, FilterTypes } from '../store';
|
||||
|
||||
export function addTodo(state: Store['todos'], id: string, label: string): Store['todos'] {
|
||||
// Write code to clone the state object while inserting a new TodoItem inside
|
||||
// - the new object must be of the type TodoItem
|
||||
// - the new state should be cloned using the spread syntax
|
||||
// - return the new state
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export function remove(state: Store['todos'], id: string) {
|
||||
// Write code:
|
||||
// - to clone the state object into new state object
|
||||
// - remove and item from the new state by using the "delete" keyword
|
||||
// - return the new state
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export function complete(state: Store['todos'], id: string) {
|
||||
// Write code:
|
||||
// - to clone the state object into new state object
|
||||
// - create a clone of the state[id] into a new item object
|
||||
// - modify new state and set the id key to the value of the new item object
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
export function clear(state: Store['todos']) {
|
||||
// Write code:
|
||||
// - to clone the state object into new state object
|
||||
// - loop through the keys of the new state object
|
||||
// - remove those items inside that new state if the item is completed using the "delete" keyword
|
||||
// - return the new state
|
||||
|
||||
return state;
|
||||
}
|
||||
Reference in New Issue
Block a user