Created
November 20, 2016 04:54
-
-
Save kevinsalter/b7d617a273cc9105b25c37dda701b186 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
import { Observable } from 'rxjs/Observable'; | |
import 'rxjs/add/observable/of'; | |
import 'rxjs/add/operator/catch'; | |
import 'rxjs/add/operator/debounceTime'; | |
import 'rxjs/add/operator/map'; | |
import 'rxjs/add/operator/mergeMap'; | |
import 'rxjs/add/operator/startWith'; | |
import { | |
isSaving, savingSuccess, savingError, | |
} from '../actions/autosave-actions.js'; | |
const saveField = (action$, null, {ajax}) => | |
action$.ofType('SAVE_FIELD') | |
.debounceTime(500) | |
.mergeMap(({payload}) => | |
ajax({ | |
method: 'PATCH', | |
url: payload.url, | |
body: JSON.stringify(payload), | |
}) | |
.map(resp => savingSuccess(resp)) | |
.catch(error => Observable.of(savingError(error))) | |
.startWith(isSaving()) | |
); | |
export default saveField; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you explain why use
startWith
here?