Previously, you created a task with createTaskType. The new API is
taskCreator, which returns a function that takes a payload.
Before, when you created a task, you set success and error as
properties on it. Now, you use map and bimap to do the same thing:
before:
// defining the "task creator"
const MY_TASK = ({payload, success, error}) => ({type: MY_TASK, payload, success, error});
// registering the handler
createTaskType(MY_TASK, task => doSideEffect(task.payload).then(task.success, task.error);
// creating a specific instance of the task type
const taskOne = MY_TASK({payload: 'hi there', success: CATS, error: DOGS});
after:
// defining the "task creator"
const MY_TASK = taskCreator((payload, success, error) =>
doSideEffect(payload).then(success, error), 'MY_TASK');
// creating a specific instance of the task type with a given payload
const taskOne = MY_TASK('hi there');
// Now you have the opportunity to use combinators before specifying the
// error/success handlers.
const taskTwo = taskOne.map(result => result + 1);
// When you're done composing and ready to hand the task off:
const taskWithHanders = taskTwo.bimap(CATS, DOGS);
Note that you use the same mechanism to add handlers (action creators) as
you do to combine behavior after a task completes: .map and .bimap.
In order to make combinators work uniformly (especially
Task.all
), we moved the success and error handlers off task instances.BREAKING CHANGE:
Because success and error are not available, you now use
succeedTaskInTest
orerrorTaskInTest
:before:
after:
BREAKING CHANGE:
Previously, you created a task with
createTaskType
. The new API istaskCreator
, which returns a function that takes a payload.Before, when you created a task, you set
success
anderror
as properties on it. Now, you usemap
andbimap
to do the same thing:before:
after:
Note that you use the same mechanism to add handlers (action creators) as you do to combine behavior after a task completes:
.map
and.bimap
.