+import { store } from 'react-recollect'; // New line
export function toggleTodo(index) {
+ store.todos[index].completed = !store.todos[index].completed; // New line
- return { type: TOGGLE_TODO, index }
}
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
| const hasLocalStorage = typeof window !== 'undefined' && !!window.localStorage; | |
| export const set = (key: string, data: any) => { | |
| if (!hasLocalStorage) return undefined; | |
| try { | |
| const string = typeof data === 'string' ? data : JSON.stringify(data); | |
| return localStorage.setItem(key, string); | |
| } catch (err) { |
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 React from 'react'; | |
| import { collect } from 'react-recollect'; | |
| const App = ({ store }) => { | |
| const { thatThing } = store.site.page.meta.data; | |
| const { anotherThing } = store.ui; | |
| const { aThirdThing } = store.maps.schemas.plans.operations; | |
| return /* ... */ | |
| }; |
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 { store } from 'react-recollect'; | |
| const loadTodos = async () => { | |
| const userId = store.user.id; | |
| store.todos = await fetch(`/api/todos/${userId}`).then((resp) => resp.json()); | |
| }; |
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
| const loadTodos = () => async (dispatch, getState) => { | |
| const userId = getState().user.id; | |
| const todos = await fetch(`/api/todos/${userId}`).then((resp) => resp.json()); | |
| dispatch({ | |
| type: 'LOADED_TODOS', | |
| data: todos, | |
| }); | |
| }; |
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
| console.assert( | |
| JSON.stringify(recollectStore.todos) === JSON.stringify(reduxStore.getState().todos), | |
| 'The two stores should match' | |
| ); |
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 { store } from 'react-recollect'; // New line | |
| export function toggleTodo(index) { | |
| store.todos[index].completed = !store.todos[index].completed; // New line | |
| return { type: TOGGLE_TODO, index } | |
| } |
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
| case SET_VISIBILITY_FILTER: | |
| return Object.assign({}, state, { | |
| visibilityFilter: action.filter | |
| }) |
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 { store } from 'react-recollect'; // New line | |
| export function setVisibilityFilter(filter) { | |
| store.visibilityFilter = filter; // New line | |
| return { type: SET_VISIBILITY_FILTER, filter }; // We'll delete this later | |
| } |
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 function setVisibilityFilter(filter) { | |
| return { type: SET_VISIBILITY_FILTER, filter }; | |
| } |