Skip to content

Commit

Permalink
test(asyn-traits): fix test after migration to angular v15 and ngrx 15
Browse files Browse the repository at this point in the history
BREAKING CHANGE: requires angular 15 and ngrx 15
  • Loading branch information
Gabriel Guerrero committed Mar 19, 2024
1 parent a4264c8 commit cbdcfba
Showing 1 changed file with 18 additions and 34 deletions.
52 changes: 18 additions & 34 deletions libs/ngrx-traits/common/src/lib/async-action/async-action.trait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,11 @@ export function addAsyncActionTrait<
`${actionsGroupKey} ${nameAsSentence} Failure`
)) as ActionCreatorWithOptionalProps<Failure>,
};
//TypeScript error after migration to 4.9.5
//Removed because 'name' is not optional
//if (name) {
return {
[`${name}`]: internalActions.request,
[`${name}Success`]: internalActions.requestSuccess,
[`${name}Fail`]: internalActions.requestFail,
} as AsyncActionActions<Request, Response, Failure, J>;
//}
//return internalActions;
return {
[`${name}`]: internalActions.request,
[`${name}Success`]: internalActions.requestSuccess,
[`${name}Fail`]: internalActions.requestFail,
} as AsyncActionActions<Request, Response, Failure, J>;
},
selectors: () => {
function isLoadingEntity<S extends AsyncActionState<J>>(state: S) {
Expand All @@ -160,32 +155,21 @@ export function addAsyncActionTrait<
// Added 'any' to 'state' and removed 'as AsyncActionState<J>'
// because OnReducer have a weird type for the state.
// TODO: Investigate if possible to remove the 'any' type and have better type safety
// tried remove the any seems to be a problex with ngrx on making the state unknown
return createReducer(
initialState,
on(
internalActions.request,
(state:any) =>
({
...state,
[`${name}Status`]: 'loading',
} )// as AsyncActionState<J>)
),
on(
internalActions.requestFail,
(state:any) =>
({
...state,
[`${name}Status`]: 'fail',
})// as AsyncActionState<J>)
),
on(
internalActions.requestSuccess,
(state:any) =>
({
...state,
[`${name}Status`]: 'success',
}) //as AsyncActionState<J>)
)
on(internalActions.request, (state: any) => ({
...state,
[`${name}Status`]: 'loading',
})),
on(internalActions.requestFail, (state: any) => ({
...state,
[`${name}Status`]: 'fail',
})),
on(internalActions.requestSuccess, (state: any) => ({
...state,
[`${name}Status`]: 'success',
}))
);
},
});
Expand Down

0 comments on commit cbdcfba

Please sign in to comment.