https://github.com/ksachdeva/angular2-store-saga-example
Example application showing how to use @ngrx/store & store-saga
https://github.com/ksachdeva/angular2-store-saga-example
Last synced: 8 months ago
JSON representation
Example application showing how to use @ngrx/store & store-saga
- Host: GitHub
- URL: https://github.com/ksachdeva/angular2-store-saga-example
- Owner: ksachdeva
- License: mit
- Created: 2016-04-20T20:42:35.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-20T18:42:29.000Z (almost 10 years ago)
- Last Synced: 2025-04-19T14:09:42.422Z (11 months ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# angular2-store-saga-example
Example application showing how to use [@ngrx/store](https://github.com/ngrx/store) & [store-saga](https://github.com/CodeSequence/store-saga)
# setup
npm install
# run
npm start
# test
http://localhost:3000
``` typescript
// a saga using angular 2 http service to get the posts
const asyncEffect2 = createSaga(function sagaFactory(http: Http) {
return function loginSaga(iteration$: Observable) {
return iteration$
.filter(iteration => iteration.action.type === DECREMENT)
.map(iteration => iteration.action.payload)
.mergeMap(payload => {
return http.get(BASE_WEB_URL + 'posts/1')
.map(res => {
return {
type: INCREMENT,
payload: res.json()
}
})
.catch(err => {
return Observable.of({
type: 'DECREMENT',
payload: err.json()
});
});
});
};
}, [Http]);
```
```typescript
// a saga using angular 2 Router to navigate to a page
const gotoAboutPageEffect = createSaga(function sagaFactory(router: Router) {
return function aboutSaga(iteration$: Observable) {
return iteration$
.filter(iteration => iteration.action.type === GOTO_ABOUT)
.map(iteration => iteration.action.payload)
.mergeMap(payload => {
return Observable.fromPromise(router.navigate(['About']))
.map(res => {
return {
type: INCREMENT
}
})
.catch(err => {
return Observable.of({
type: 'DECREMENT'
});
});
});
};
}, [Router]);
```