+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 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 List = (props: { | |
items: any[]; | |
renderItem: (item: any) => React.ReactNode; | |
}) => ( | |
<>{props.items.map(props.renderItem)}</> | |
); |
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
<List | |
items={notProducts} | |
renderItem={notAProduct => ( | |
<p> | |
{notAProduct.name}: {notAProduct.code} | |
</p> | |
)} | |
/> |
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
<List | |
items={products} | |
renderItem={product => ( | |
<p> | |
{product.name}: ${product.proice} | |
</p> | |
)} | |
/> |
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 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 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 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 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 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 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 } | |
} |