Skip to content

Instantly share code, notes, and snippets.

@kevinsalter
Created November 20, 2016 04:52
Show Gist options
  • Save kevinsalter/e5b53c05d16a54aa79f2ad53447e6b5a to your computer and use it in GitHub Desktop.
Save kevinsalter/e5b53c05d16a54aa79f2ad53447e6b5a to your computer and use it in GitHub Desktop.
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