QuickStart
Core Modules
Simple API and tiny volume。
State updates are completely limited to reducers, and centralized management of update operations makes state changes more predictable。
Running independently of any framework.
TIP
Slim can be applied to any framework because it does not depend on any framework. Integration to frameworks will very easy by using Plugin.
<script src="https://unpkg.com/slim-store@latest/slim.min.js"></script>
npm install slim-store
yarn add slim
import Slim from 'slim-store'
// state is single object
const state = {
name: 'slim',
age: 20
}
// reducers are event proxies
const reducers = {
increment: (state) => {
state.age += 1
}
}
// getters are computed functions of state
const getters = {
desc: state => `My name is : ${state.name}, I'm ${state.age}-years-old!`
}
// create store
const store = Slim.createStore({
reducers,
getters,
state
})
// emit increment reducer
store.commit('increment')
console.log(store.state.count)
// output: 21
console.log(store.getGetter('desc'))
// output: My name is : slim, I'm 21-years-old!`