Gathering detailed insights and metrics for clean-state
Gathering detailed insights and metrics for clean-state
Gathering detailed insights and metrics for clean-state
Gathering detailed insights and metrics for clean-state
redux-clean-state
A higher order component to clean your app state on componentWillUnmount
use-state-validate
Clean featherweight state validation
react-state-view-controller
A clean state management library for React/React Native. Effectively separate logic and UI
@cleanweb/react
A suite of helpers for writing cleaner React function components.
npm install clean-state
Typescript
Module System
Node Version
NPM Version
48.7
Supply Chain
95.8
Quality
75.6
Maintenance
100
Vulnerability
100
License
TypeScript (82.74%)
JavaScript (17.26%)
Total Downloads
3,701
Last Day
1
Last Week
7
Last Month
35
Last Year
365
119 Stars
82 Commits
16 Forks
8 Watching
1 Branches
15 Contributors
Minified
Minified + Gzipped
Latest Version
2.2.4
Package Id
clean-state@2.2.4
Unpacked Size
15.57 kB
Size
6.18 kB
File Count
10
NPM Version
6.14.8
Node Version
12.19.0
Cumulative downloads
Total Downloads
Last day
-50%
1
Compared to previous day
Last week
75%
7
Compared to previous week
Last month
400%
35
Compared to previous month
Last year
-47.6%
365
Compared to previous year
3
🐻 Clean-State is a neat, compact state management tool. It drops all of React's historical baggage, uses native hooks to implement it, and gets rid of Redux's problem of invalid rendering during status updates. At the architectural level it is automatically organized through a very simple API. 🍋 If you're not building an aircraft carrier and you're tired of having a large, complex and unwield-of-use State management library, try clean-state. It is small and exquisite, the performance of the extreme can meet your needs.
1npm i clean-state --save
1// modules/user.ts 2const state = { 3 name: 'test' 4} 5 6const user = { 7 state, 8 reducers: { 9 setName({payload, state}) { 10 return {...state, ...payload} 11 } 12 }, 13 effects: { 14 async fetchNameAndSet({dispatch}) { 15 const name = await Promise.resolve('fetch_name') 16 dispatch.user.setName({name}) 17 } 18 } 19} 20 21export default user;
1// modules/index.ts 2import user from './user' 3import bootstrap from 'clean-state' 4 5const modules = { user } 6export const {useModule, dispatch} = bootstrap(modules);
1// page.ts 2import {useCallback} from 'react' 3import { useModule, dispatch } from './modules' 4 5function App() { 6 /** 7 * Here you can also pass in an array and return multiple module states at the same time 8 * const {user, project} = useModule(['user', 'project']) 9 */ 10 const { user } = useModule('user') 11 const onChange = useCallback((e)=> { 12 const { target } = e 13 dispatch.user.setName({name: target.value}) 14 }, []) 15 16 const onClick = useCallback(()=> { 17 dispatch.user.fetchNameAndSet() 18 }, []) 19 20 return ( 21 <div className="App"> 22 <div> 23 <div> 24 name: {user.name} 25 </div> 26 <div> 27 modify: <input onChange={onChange}></input> 28 </div> 29 <button onClick={onClick}>getUserName</button> 30 </div> 31 </div> 32 ); 33} 34 35export default App;
In many cases, there are common states, reducers, or effects between multiple modules, and here we expose the methods to prevent users from making duplicate declarations in each module.
1// common.ts 2const common = { 3 reducers: { 4 setValue<State>({payload, state}: {payload: Record<string, any>, state: State}): State { 5 return {...state, ...payload} 6 } 7 } 8} 9export default common; 10 11// modules/index.ts 12import commont from './common' 13import user from './user' 14import { mixin } from 'clean-state'; 15 16// Mix Common's setValue method into the User module 17const modules = mixin(common, { user }) 18 19// You can now call the dispatch.user.setValue method on other pages 20export const {useModule, dispatch} = bootstrap(modules); 21
state
Module state, which is a property object.
{
name: 'zhangsan',
order: 1
}
reducers
A collection of handlers that change the state of a module, returning the latest state.
{
setValue({payload, state, rootState}) {
return {...payload, ...state}
}
}
effects
Module's collection of side effects methods that handle asynchronous calls.
{
async fetchAndSetValue({payload, state, rootState, dispatch}) {
const newOrder = await fetch('xxx')
dispatch.user.setValue({order: newOrder})
}
}
bootstrap(modules)
Property | Description | Type |
---|---|---|
modules | A collection of registered modules | {string, Module} |
useModule(moduleName)
Property | Description | Type |
---|---|---|
moduleName | The name of the module used returns the corresponding status | string / string[] |
mixin(common, modules)
Property | Description | Type |
---|---|---|
common | Public modules that need to be injected | Module |
modules | A collection of registered modules | Module |
dispatch.{moduleName}.{fnName}(payload)
Property | Description | Type |
---|---|---|
moduleName | The specific module name of the call should be registered in Bootstrap | string |
fnName | The method name of the call module, reducer/effect | string |
payload | The load value passed | object |
You can use cs-redux-devtool to debug your project and track historical data changes.
Dispatch calls take precedence at effects-> reducers, so when there are reducers and effects with the same name under a module, only effects are executed.
If you have better suggestions for this library, or have any problems using it, you can write them here: https://github.com/tnfe/clean-state/issues
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More