I have JSON that is in my effect that was initially a JSON.stringify(state) and need to add that JSON string back into the state to update the app. (New to Angular and NgRx/Redux).
I have an effect like so (which I'm probably doing wrong):
@Effect({ dispatch: false })
upState$ = this.actions$.pipe(
ofType(WorkspaceActionTypes.UpState),
withLatestFrom(this.store.select(fromSpace.getState)),
tap(([empty, space]) => {
console.log(JSON.stringify(space));
var json = "my json file in string form";
space = json;
})
);
The json can't go from a string to a type State.
UPDATE:
After looking at the link in the comments, am I supposed to create an effect that calls an action that calls a reducer to update the state? I see this from the link but not sure how to use it yet:
@Effect()
createArticle$: Observable<Action> = this.actions$
.ofType<fromActions.CreateAction>(fromActions.CREATE)
.map(action => action.payload)
.mergeMap(article =>
this.articleService.createArticle(article)
.map(res => new fromActions.CreateSuccessAction(res))
.catch(error => of(new fromActions.CreateFailureAction(error)))
);
store.select
, which returns an object) and then what? You want to stringify the state to populate another property inside your store? You want to change it and update the store with a new value? Couldn't really understand. – João GhignattiUpStateSuccess
and update the state in your reducer for that action, effects MUST NOT update the store – Reza