Oct 8, 2023
Exploring fp-ts, building off the previous application to create a more oure network connection.
// import "../../lab_modules/035";
The Application
In the previous lab we built a simple shopping application using fp-ts
. In
this lab we will build off the previous application to create a more pure
network connection. From the learning of
pure network request with TaskEither,
I'll refactor the application and presentation layer to include the
useTaskEither
hook and seperate the fetchProduct
from the useShoppingCart
hook.
Application Layer
The refactored application layer adds the useTaskEither
hook. This hook is
responsible for running the TaskEither
and updating the state of the
application. It also adds the match
function. This function is responsible for
pattern matching over all possible states of the application. This allows us to
seperate the states of the application in the presentation layer.
I've also seperated the fetchProduct
function from the useShoppingCart
hook.
Presentation Layer
The refactored presentation layer uses the match
function to pattern match
over all possible states of the application. This allows us to seperate the
states of the application in the presentation layer.