Skip to content

Instantly share code, notes, and snippets.

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

mrdulin commented Jul 20, 2017

Can you explain why use startWith here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment