Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //App.JS
- ....
- import configureStore from './src/store/configureStore';
- const store = configureStore();
- class App extends Component {
- render() {
- return (
- <Provider store={store}>
- <View style={{ flex: 1 }}>
- <StatusBar backgroundColor="#285576" />
- <MyForm />
- </View>
- </Provider>
- );
- }
- }
- export default App;
- import { applyMiddleware, createStore } from 'redux';
- import createSagaMiddleware from 'redux-saga';
- import reducers from './../reducers';
- import rootSaga from './../sagas/rootSaga';
- export default function configureStore() {
- const sagaMiddleware = createSagaMiddleware();
- const store = createStore(reducers, applyMiddleware(sagaMiddleware));
- sagaMiddleware.run(rootSaga);
- return store;
- }
- ...
- <TouchableOpacity style={{ backgroundColor: '#4368b2', borderColor: '#3464c8', borderRadius: 5 }}
- onPress={login(this.props.email,this.props.password)}> //call login action
- <Text style={commonStyle.buttonText}>{this.props.type}</Text>
- </TouchableOpacity>
- ...
- export function login(email, password) {
- console.log('action-login');
- return {
- type: LOGIN_ACTION,
- username: email,
- password
- };
- }
- import { all, fork } from 'redux-saga/effects';
- import { loginFlow } from './AuthSagas';
- export default function* rootSaga() {
- yield fork(loginFlow);
- }
- import { put, call, take } from 'redux-saga/effects';
- import { takeEvery } from 'redux-saga';
- import auth from './../auth';
- import { LOGIN_ACTION } from './../action/types';
- import { setLoginSuccess, setLoginError } from './../action';
- function* authorize(credentials) {
- try {
- const token = yield call(auth.login(credentials));
- console.log(token);
- if (!token.error) {
- yield put(setLoginSuccess(token, credentials.username, credentials.password));
- return token;
- }
- yield put(setLoginError(token));
- return undefined;
- } catch (error) {
- console.log(error);
- return undefined;
- }
- }
- export function* loginFlow() {
- console.log('saga-alert');
- const { username, password } = yield take(LOGIN_ACTION);
- yield call(authorize, { username, password });
- }
Add Comment
Please, Sign In to add comment