This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeDispatcher } from "../src/redux/store/dispatch.js"; | |
import assert from "assert"; | |
describe("dispatch.js", () => { | |
describe("makeDispatcher", () => { | |
it("generates a function from state handlers, a reducer and a callback", () => { | |
const stateHandlers = { | |
getState() {}, | |
setState(arg) {}, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const makeSubscriber = (subscribers) => ({ | |
subscribe(callback) { | |
subscribers.push(callback); | |
}, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeSubscriber } from "../src/redux/store/subscribe.js"; | |
import assert from "assert"; | |
describe("subscribe.js", () => { | |
describe("makeSubscriber", () => { | |
it("generates a function from subscribers", () => { | |
const subscribers = []; | |
const subscriber = makeSubscriber(subscribers); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { makeSubscriber } from "./subscribe"; | |
import { makeStateHandlers } from "./state"; | |
import { makeDispatcher } from "./dispatch"; | |
export const createStore = (reducer, initialState = {}) => { | |
const stateContainer = [initialState]; | |
const subscribers = []; | |
const stateHandlers = { | |
...makeStateHandlers(stateContainer), | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { generateId } from "../id/index.js"; | |
export const createTodoBase = (text) => ({ text, done: false }); | |
export const createTodoItem = (todoObj, idObj) => ({ | |
...todoObj, | |
...idObj, | |
}); | |
export const getTodoItem = (text) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
createTodoBase, | |
createTodoItem, | |
getTodoItem, | |
} from "../src/factories/todo/index.js"; | |
import assert from "assert"; | |
describe("factories", () => { | |
describe("todo", () => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const CONSTS = { | |
actions: { | |
ADD: "ADD", | |
DELETE: "DELETE", | |
UNDO: "UNDO", | |
REDO: "REDO", | |
TOGGLE: "TOGGLE", | |
SET_VISIBILITY: "SET_VISIBILITY", | |
}, | |
visibilityFilters: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CONSTS } from "../actions"; | |
const { | |
actions: { SET_VISIBILITY }, | |
visibilityFilters: { ALL }, | |
} = CONSTS; | |
export const setVisibility = (state, filter) => filter; | |
export const visibilityReducer = (state = ALL, action) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CONSTS } from "../actions/index.js"; | |
const { | |
actions: { ADD, DELETE, TOGGLE }, | |
} = CONSTS; | |
export const addTodo = (state, newTodo) => [...state, newTodo]; | |
export const deleteTodo = (state, id) => state.filter((todo) => todo.id !== id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { CONSTS } from "../actions/index.js"; | |
const { | |
actions: { UNDO, REDO }, | |
} = CONSTS; | |
/* | |
Read more at: | |
https://redux.js.org/recipes/implementing-undo-history |