×

unistore微型集中式状态容器

消耗积分:0 | 格式:zip | 大小:0.02 MB | 2022-05-11

479809

分享资料个

授权协议 MIT
开发语言 JavaScript
操作系统 跨平台
软件类型 开源软件
所属分类 云计算PaaS系统/容器

软件简介

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 }) => (
		

Count: {count}

Increment
) ) export default () => ( )
 

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !