![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
🐻 一款纯净小巧的状态管理器,使用react-hooks原生实现,自动连接module组织架构。🍋如果你不是要制造一艘航空母舰又厌烦了复杂且难用的大型状态管理库,那么不妨来试试Clean-State。它小巧玲珑、性能极致完全可以满足你的需求。
npm i clean-state --save
// user.ts
export default {
state: {
name: ''
},
reducers: {
setName(payload, currentState) {
const { name } = payload
return {...currentState, name}
}
},
effects: {
async getUser{payload, rootState, dispatch}) {
const { uId } = payload
const user = await fetch.get(`xxx?uid=${uId}`)
dispatch.user.setName({name: user.name})
}
},
};
// index.ts
import createContainer, { bootstrap } from 'clean-state';
import user from 'user'
const modules = {user}
const setUp = bootstrap(modules);
const cState = createContainer(setUp.useHook);
export const { initialState } = setUp;
export const { Provider, useModule } = cState;
// app.ts
import Container, { initialState } from 'index.ts';
function MyApp({ Component, pageProps }: AppProps): React.ReactElement {
// todo: here can modify initialState
return <Container.Provider initialState={initialState}>
<Component {...pageProps} />
</Container.Provider>;
}
// page.ts
import { useModule } from 'index.ts';
function Page() {
const [state: {user}, dispatch] = useModule()
const change = useCallback(()=> {
const payload = { name: 'test' }
dispatch.user.setName(payload)
}, [])
return <div>
<button onClick={change}>modify</button>
{user.name}
<div>
}
在很多情况下,多个module之间会存在公共的state、reducers或者effects。
// common.ts
export default {
reducers: {
setValue<T>(payload: Record<keyof T, any>, state: T): T {
return { ...state, ...payload };
},
},
};
// index.ts
import commont from 'common'
import user from 'user'
import { mixin } from 'src/store';
// user 模块混入了common的setValue方法
const modules = mixin(common, { user })
...
Dispatch优先级为 effects -> reducers,同模块下函数不允许同名。
clean-state在MIT License下允许使用。
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.