4 ms·
I also don't like having all those constants like LOADING_PRODUCTS ... And I don't have them, instead this is how you create a type safes actions with typesafe
by alfonsodev 6y ago
I also don't like having all those constants like LOADING_PRODUCTS ...
And I don't have them, instead this is how you create a type safes actions with typesafe-actions package.
export const signIn = {
request: createAction("auth/signin/request")(),
success: createAction("auth/signin/success")<{ user: User }>(),
error: createAction("auth/signin/error")<Error>(),
};
getType is a function from typesafe-actions as well.
Not trying to sell you on Redux, just to address your point about the constants.
About having to write many Epics, well, end of the day, all the Epics have this shape.
export const signInEpic = (action$: Observable<Action>) =>
action$.pipe(
filter(isActionOf(signIn.request)),
switchMap(() =>
from(signInLogic()).pipe(
map((user: User) => {
return signIn.success({ user });
}),
catchError((error) => of(signIn.error(error)))
)
)
);
isActionOf is another typesafe-actions function...
I'm not claiming it's superior approach or faster, it's an approach that worked for me for medium/large apps, to collaborate with other developers.
I'm pretty sure you are right about the Svelte cool things you saying I wish I had more time to look into it.
- acemarke 6y agoWe specifically recommend using our official Redux Toolkit package, rather than `typesafe-actions`. RTK is already written in TS and designed for a solid TS usage experience: https://redux-toolkit.js.org https://redux-toolkit.js.org
- skvark 6y agoRedux Toolkit is great and removes most of the usual Redux boilerplate which seems to be the most often used argument against Redux. Additionally, I usually use a function which uses createEntityAdapter, createSlice and createAsyncThunk methods to create Ducks bundles for each REST API resource automatically. As a result I get all async action creators, reducers and basic selectors for some REST API resource with a couple of lines of code.
- acemarke 6y agoIf you like the stuff in RTK so far, I think you're going to like our upcoming "RTK Query" API, which adds a React Query-inspired data fetching abstraction: https://rtk-query-docs.netlify.app https://rtk-query-docs.netlify.app We're working on finalizing that API and will be merging the functionality and docs back into RTK itself for an upcoming RTK release: https://github.com/rtk-incubator/rtk-query/issues/175 https://github.com/rtk-incubator/rtk-query/issues/175
- skvark 6y agoRTK Query looks great, I'll check it out.
- alfonsodev 6y agothanks! I resisted redux-toolkit when it came out, but looking at the website, it might be the time to update the stack :)