![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
redux-machine-immutable
Advanced tools
A tiny lib for creating state machines as swappable Redux reducers that operate on Immutable JS Maps
A tiny lib (16 lines) for creating state machines as swappable Redux reducers
This is the version of this library to use when your Redux store state is an Immutable JS Map. See also the non-immutable-js version of redux-machine.
redux-machine enables you to create reducers that can transition between different "statuses." These are likes states in a finite state machine. The goal is for redux-machine to support complex workflows simply while keeping all state in the redux store. Keeping all state in the store is good because:
npm install redux-machine --save
redux-machine internally uses Object.assign, which is an ES2015 feature. If you need to support older browsers, you can use a polyfill such as core-js.
This is the entire API for redux-machine:
// entire API, no middleware required
import { createMachine } = from './index.js'
const fetchUsersReducer = createMachine({
'INIT': initReducer,
'IN_PROGRESS': inProgressReducer
})
The reducer returned by createMachine
will act like initReducer
when its status is INIT
and will act like inProgressReducer
when the status is IN_PROGRESS
. If the store's state.status
is undefined, the reducer for INIT
is used (so it's a good idea to provide a reducer for the INIT
status).
initReducer
and inProgressReducer
can do status transitions by setting state.status
:
const initReducer = (state = {error: null, users: []}, action) => {
switch (action.type) {
case 'FETCH_USERS':
return state
.set('error', null)
.set('status', 'IN_PROGRESS')
})
default:
return state
}
}
const inProgressReducer = (state = {}, action) => {
switch (action.type) {
case 'FETCH_USERS_RESPONSE':
return state.withMutations(map => {
return map
.set('error', null)
.set('users', action.payload.users)
.set('status', 'INIT')
})
case 'FETCH_USERS_FAIL':
return state
.set('error', action.payload.error)
.set('status', 'INIT')
return state
.set('error', action.payload.error)
.set('status', 'INIT')
default:
return state
}
}
The example above defines the following state machine:
In words:
INIT
and the action type is FETCH_USERS
, the machine transitions to IN_PROGRESS
status.IN_PROGRESS
and the action type is FETCH_USERS_RESPONSE
or FETCH_USERS_FAIL
, the machine transitions to the INIT
(initial) status.You don't need redux-machine, since you can accomplish almost the same thing as in the example above by defining fetchUsersReducer
as follows:
const fetchUsersReducer = (state, action) => {
switch (state.get(status)) {
case 'INIT':
return initReducer(state, action)
case 'IN_PROGRESS':
return inProgressReducer(state, action)
default:
return initReducer(state, action)
}
}
The (marginal) advantages of using redux-machine over just using the FSM pattern is that you can more clearly express intent and write slightly less code.
These examples use the non-immutable-js version of redux-machine.
FAQs
A tiny lib for creating state machines as swappable Redux reducers that operate on Immutable JS Maps
The npm package redux-machine-immutable receives a total of 2 weekly downloads. As such, redux-machine-immutable popularity was classified as not popular.
We found that redux-machine-immutable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.