Created
November 18, 2019 23:49
-
-
Save whitelizard/5e45deedb55c6aaad75422d586bfa141 to your computer and use it in GitHub Desktop.
Functional style Immutable Store tests
This file contains 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
const initialState = { | |
1: circle([2.5, 0], 1.5), | |
2: circle([-2, 0], 2), | |
}; | |
const { getState, dispatch } = createStore(initialState, reducer); | |
area(getState(1).r); // -> 7.0685834705770345; | |
area(getState(2).r); // -> 12.566370614359172; | |
const [hit] = intersect(getState(1), getState(2)); | |
hit; // -> false | |
if (hit) dispatch({ type: 'hit', id1: 1, id2: 2 }); | |
getState(1).hits; // -> 0 | |
dispatch({ type: 'move', payload: [1, 0], id: 1 }); | |
const [hit2] = intersect(getState(1), getState(2)); | |
hit2; // -> true | |
if (hit2) dispatch({ type: 'hit', id1: 1, id2: 2 }); | |
getState(1).hits; // -> 1 | |
getState(2).hits; // -> 1 | |
initialState[1].hits = 4; // -> THROWS! | |
getState(1).hits = 4; // -> THROWS! | |
getState(1).hits; // -> 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment