Last active
November 6, 2017 13:02
-
-
Save cmilfont/a0009b8e0af3e4ce0eb1e23439324314 to your computer and use it in GitHub Desktop.
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
// model error | |
import { Record, fromJS, Map } from 'immutable'; | |
export default class ErrorRecord extends Record({ | |
warnings: Map(), | |
form: Map(), | |
fatal: Map(), | |
}) { | |
constructor(values) { | |
// sua lógi a | |
} | |
}; | |
//Reduce error.js | |
import ErrorRecord from 'api/models/error'; | |
export default (state = new ErrorRecord(), action) => { | |
if (action.type.match(/ERROR/) { | |
const error = {/* prepara o tipo { fatal: action.payload } */} | |
return new ErrorRecord(error); | |
} | |
return state; | |
} | |
// Exemplo de Saga pedindo a localização do usuário | |
export function * verifySaga() { | |
try { | |
const position = yield localforage.getItem('position'); | |
if (position) { | |
yield put(verifiedPosition({ | |
...position, | |
verified: true, | |
})); | |
} else { | |
yield put(verifiedPosition({ | |
verified: true, | |
currentPositionMessage: 'Precisamos da sua localização' | |
})); | |
} | |
} catch (error) { | |
yield put(globalException(error)) | |
} | |
} | |
// App.js | |
class App extends React.Component { | |
error = payload => (this.store.dispatch({ | |
type: action.GLOBAL_EXCEPTION, | |
payload, | |
})) | |
componentWillMount() { | |
const sagaMiddleware = createSagaMiddleware({ onError: this.onError }); | |
const composeEnhancers = composeWithDevTools({}); | |
this.history = createHistory(); | |
const routerReduxMiddleware = routerMiddleware(this.history); | |
const middlewares = [ | |
routerReduxMiddleware, | |
/* INJETAR OU CRIAR SEU MIDDLEWARE DE TRACKING */ | |
RavenMiddleware('my-sentry-dsn'), | |
sagaMiddleware, | |
]; | |
this.store = createStore( | |
combineReducers({ | |
...reducers, | |
router: routerReducer | |
}), | |
composeEnhancers(applyMiddleware(...middlewares)) | |
); | |
sagaMiddleware.run(sagas) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment