0

The tasks this code is trying to accomplish are these in order

  1. Im trying to listen for an action

  2. take the payload for that action

  3. pass that payload to a database service function

  4. pass the payload to a success reducer action

The data is supposed to be getting saved to Indexeddb in the browser but keeps giving me an error saying its being provided a null value which is not true.

what could be causing a null value to be passed?

@Effect()
public createCampaign$ = this.actions$.pipe(
        ofType(ActionTypes.CREATE_CAMPAIGN),
        map((action: CampaignActions.CreateCampaignAction) => action.payload),
        switchMap((payload) => this.databasService.addCampaign(payload).then(() => Promise.resolve(payload).then(item => item))),
        map((campaign) => (new CampaignActions.CreateCampaignSuccessAction(campaign)))

)
Shashank Vivek
  • 16,888
  • 8
  • 62
  • 104
Siddartha
  • 175
  • 1
  • 8
  • can you explain what are you expecting from this? `this.databasService.addCampaign(payload).then(() => Promise.resolve(payload).then(item => item))`. Are you trying to return the same payload you are sending to the service or you are expecting result from the service? – Kamrul Oct 01 '18 at 22:25
  • I'm expecting it to return a promise then returning the same value to the success action – Siddartha Oct 02 '18 at 03:50
  • `Promise.resolve(payload).then(item => item)` means you are essentially returning the `payload` as promise, which is same as returning `Promise.resolve(payload)`. Now you need to turn promise to observable to get it in the outer operator. you can consider using `fromPromise` operator. Hope this helps. – Kamrul Oct 02 '18 at 22:03

0 Answers0