![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
clean-state
Advanced tools
🐻 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.
npm i clean-state --save
// modules/user.ts
const state = {
name: 'test'
}
const user = {
state,
reducers: {
setName({payload, state}: any) {
return {...state, ...payload}
}
},
effects: {
async fetchNameAndSet({dispatch}: any) {
const name = await Promise.resolve('fetch_name')
dispatch.user.setName({name})
}
}
}
export default user;
// modules/index.ts
import user from './user'
import bootstrapfrom 'clean-state'
const modules = { user }
export const {useModule, dispatch} = bootstrap(modules);
// page.ts
import {useCallback} from 'react'
import { useModule, dispatch } from './modules'
function App() {
const { user } = useModule('user')
const onChange = useCallback((e)=> {
const { target } = e
dispatch.user.setName({name: target.value})
}, [])
const onClick = useCallback(()=> {
dispatch.user.fetchNameAndSet()
}, [])
return (
<div className="App">
<div>
<div>
name: {user.name}
</div>
<div>
modify: <input onChange={onChange}></input>
</div>
<button onClick={onClick}>getUserName</button>
</div>
</div>
);
}
export 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.
// common.ts
const common = {
reducers: {
setValue<State>({payload, state}: {payload: Record<string, any>, state: State}): State {
return {...state, ...payload}
}
}
}
export default common;
// modules/index.ts
import commont from './common'
import user from './user'
import { mixin } from 'clean-state';
// Mix Common's setValue method into the User module
const modules = mixin(common, { user })
// You can now call the dispatch.user.setValue method on other pages
export const {useModule, dispatch} = bootstrap(modules);
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 |
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
FAQs
English | 中文
The npm package clean-state receives a total of 2 weekly downloads. As such, clean-state popularity was classified as not popular.
We found that clean-state 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
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.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.