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 { 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
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 { 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 makeStateHandlers = (stateContainer) => ({ | |
getState() { | |
const [lastState] = stateContainer.slice(-1); | |
return lastState; | |
}, | |
setState(newState) { | |
return stateContainer.push(newState); | |
}, | |
}); |
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 makeDispatcher = (stateHandlers, reducer, onDispatch) => ({ | |
dispatch(action) { | |
const { getState, setState } = stateHandlers; | |
const state = getState(); | |
const newState = reducer(state, action); | |
setState(newState); | |
onDispatch(); |
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 { makeStateHandlers } from "../src/redux/store/state.js"; | |
import assert from "assert"; | |
describe("state.js", () => { | |
describe("makeStateHandlers", () => { | |
it("generates two functions from a state container input", () => { | |
const stateContainer = [{ state: "state" }]; | |
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
<html> | |
<head> | |
<title>Todo App</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body> | |
<script src="./index.js"></script> | |
</body> | |
</html> |
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 assert from "assert"; | |
const compose = (...functions) => (initialArg) => | |
functions.reduceRight( | |
(accumulatedValue, func) => func(accumulatedValue), | |
initialArg | |
); | |
describe("compose", () => { | |
it("returns a composed function h, so that h(x) is equal to f(g(x))", () => { |
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
<# | |
Gitbot | |
Makes Your Git Stats Great | |
#> | |
param([string]$path="C:\") | |
function GenerateName { | |
$filepath = Resolve-Path "words.txt" | |
$raw = Get-Content -Path $filepath |