1

I'm new to Redux and Redux-Observable. I'm having success in getting information from a rest API with GET and GET(ID), but I cannot get the Delete and Post to work. Sample code below that is issuing a GET request:

[EPIC File]
import { debounceTime, Observable } from 'rxjs';
import { ajax } from 'rxjs/observable/dom/ajax';
import ActionTypes from '../actions/ActionTypes';
import { receiveFeedBack, receiveDeleteFeedBackId,
receiveFeedBackId } from '../actions/FeedBackActions';


export const fetchFeedBack = (action$) =>      ... Working
export const fetchFeedBackId  = (action$) =>   ... Working

//Not Working
export const deleteFeedBackById = (action$) =>
  action$.ofType(ActionTypes.DELETE_FEEDBACK_REQUEST)
  .debounceTime(500)
  .switchMap(action =>
    ajax.delete(`${ActionTypes
      .FEEDBACK__URL}/posts/${action.payload.feedbackId}?key=${ActionTypes
      .FEEDBACK__API_KEY}`)
      .map(receiveDeleteFeedBackId.bind(action))
      .takeUntil(action$.ofType(ActionTypes.DELETE_FEEDBACK_CANCELED))
      .catch(error => Observable.of({
        type: ActionTypes.DELETE_FEEDBACK_ERROR,
        payload: error
      }))
);

What am I doing wrong?

Beosfreak
  • 31
  • 1
  • 4
  • It sounds like you're saying `ajax.delete(...)` makes a _GET_ requests, instead of a _DELETE_? Can you describe what happens? Do you get an error? What error? – jayphelps Nov 20 '16 at 19:21
  • Is this trying to make it cross-domain? Do you receive any CORS errors in the console? – jayphelps Nov 20 '16 at 19:22
  • Thank you jayhelps, it seems your simple comments made me look at my code again. Actually for the second day!. It turns out that I forgot to add the "deleteFeedBackById" method to the "combineEpics" file. Sharing: I had this working with redux-promise, then I changed to redux-thunk for async. Realizing I need additional features like cancel request, I searched the web, found your's and Ben's AWESOME video and have begun the conversion to redux-observables. So, thank you for your quick feedback and many thanks for the video. – Beosfreak Nov 21 '16 at 00:37
  • ah got it, so it wasn't doing anything cause it wasn't included in the root epic so it never runs. Cheers! – jayphelps Nov 21 '16 at 00:49
  • Exactly. Again,thanks for this "Most Excellent" product. For me, its is a "Must Have" package for any Redux Enabled App. – Beosfreak Nov 21 '16 at 11:41

0 Answers0