unistore 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
unistore 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
unistore 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
所属分类 云计算PaaS系统/容器
开源组织
地区 不详
投 递 者 王练
适用人群 未知
收录时间 2017-12-07

软件简介

unistore 是一个微型(650B)的集中式状态容器。

特性

  • 非常小却很好地遵循了 Preact 的步伐

  • 类似 Redux 的熟悉的命名和思路

  • 有用的数据选择器,可从状态中提取属性

  • 便携式的操作,可移动到一个通用的地方并导入

  • 简化是唯一目标

Usage

import { Provider, createStore, connect } from 'unistore'

let store = createStore({ count: 0 })

// If actions is a function, it gets passed the store:
let actions = store => ({
	// Actions can just return a state update:
	increment(state) {
		return { count: state.count+1 }
	},

	// The above example as an Arrow Function:
	increment2: ({ count }) => ({ count: count+1 }),

	// Async actions can be pure async/promise functions:
	async getStuff(state) {
		let res = await fetch('/foo.json')
		return { stuff: await res.json() }
	},

	// ... or just actions that call store.setState() later:
	incrementAsync(state) {
		setTimeout( () => {
			store.setState({ count: state.count+1 })
		}, 100)
	}
})

const App = connect('count', actions)(
	({ count, increment }) => (
		<div>
			<p>Count: {count}</p>
			<button onClick={increment}>Increment</button>
		</div>
	)
)

export default () => (
	<Provider store={store}>
		<App />
	</Provider>
)
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣 发布并加入讨论🔥
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
0 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部