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 {createStore, applyMiddleware, compose} from 'redux'; | |
import thunk from 'redux-thunk'; | |
import indexReducer from './reducers/index'; | |
import {persistStore, autoRehydrate} from 'redux-persist'; | |
import {AsyncStorage} from 'react-native'; | |
const store = compose(applyMiddleware(thunk), autoRehydrate())(createStore)(indexReducer) | |
persistStore(store, {blacklist: [], storage: AsyncStorage}); |
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
// store.js加入redux-thunk | |
import {createStore, applyMiddleware, compose} from 'redux'; | |
import thunk from 'redux-thunk'; | |
import indexReducer from './reducers/indexReducer'; | |
const store = compose(applyMiddleware(thunk))(createStore)(indexReducer); | |
export default store; |
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
//actions改為thunk版本 | |
import * as Types from '../types'; | |
export function addTodo(todo) { | |
return (dispatch) => { | |
dispatch({ | |
type: Types.ADD_TODO, | |
payload: todo, | |
}) |
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, { Component } from 'react'; | |
import { View, TextInput, Text, Button } from 'react-native'; | |
import {connect} from 'react-redux'; | |
import {bindActionCreators} from 'redux'; | |
import {addTodo, toggleTodo} from '../actions/todo.js'; | |
const mapStateToProps = (state) => { | |
return { | |
todos: state.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
import React, { Component } from 'react'; | |
import { View, TextInput, Text, Button } from 'react-native'; | |
import store from '../store'; | |
import * as Types from '../types'; | |
import {connect} from 'react-redux'; | |
const mapStateToProps = (state) => { | |
return { | |
todos: state.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
// @flow | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import store from './app/store'; | |
import Todo from './app/components/Todo' | |
const App = (props) => { | |
return ( | |
<Provider store={store}> |
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 {combineReducers} from 'redux'; | |
import todos from './todos'; | |
const indexReducer = combineReducers({ | |
todos, | |
}); | |
export default indexReducer; |
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 * as Types from '../types'; | |
const initialState = []; | |
export default function(state = initialState, action = {}) { | |
switch (action.type) { | |
case Types.ADD_TODO: | |
return [...state , action.payload]; | |
case Types.TOGGLE_TODO: | |
let filteredTodos = state.filter((todo) => todo.id !== action.payload.id); |
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, { Component } from 'react'; | |
import { View, TextInput, Text, Button } from 'react-native'; | |
import store from './app/store'; | |
import * as Types from './app/types'; | |
export default class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: null, |
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 {createStore} from 'redux'; | |
import indexReducer from './reducers/indexReducer'; | |
const store = createStore(indexReducer); | |
export default store; | |