Created
November 20, 2016 04:52
-
-
Save kevinsalter/e5b53c05d16a54aa79f2ad53447e6b5a 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/dom/ajax'; | |
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$ => | |
action$.ofType('SAVE_FIELD') | |
.debounceTime(500) | |
.mergeMap(({payload}) => | |
Observable.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