Clarification on Correct Use of 'Side Effects' in ngrx/effects

Is optimistic state update safe in ngrx/effects when API errors force rollback? Example:

@Effect() ef=act$.pipe(ofType('CREATE'),mergeMap(a=>srv.put(a).pipe(map(()=>({t:'OK',i:a.id})),catchError(()=>of({t:'ERR',i:a.id})))));

Based on my experience with ngrx implementation, I’ve worked extensively with optimistic state updates and found them quite effective for a smooth user experience, provided that a comprehensive error handling strategy is in place. In one project, we had to deal with intermittent network issues that occasionally required reverting state changes. We overcame this challenge by ensuring that our rollback logic was both fast and reliable, testing every scenario thoroughly. This also meant closely monitoring the API responses and incorporating redundant checks in our effects to handle any delays in error propagation.

From my experience using ngrx with optimistic updates, I found it essential to carefully manage error handling and rollback mechanisms. In one project, I implemented a strategy where reusable rollback actions were triggered immediately after an API error was detected, ensuring state consistency was maintained. The key was to decouple the optimistic update from the API call while verifying each response meticulously. This approach allowed for clear separation of state logic and error handling within the effects, ultimately leading to more robust state management in the face of intermittent API failures.