nicedog
Easydog 是一个前端状态管理工具,简化开发体验。适合小程序等项目等的开发。
Last updated 3 months ago by whistleyz .
ISC · Original npm · Tarball · package.json
$ cnpm install nicedog 
SYNC missed versions from official npm registry.

Easydog

Easydog 是一个前端状态管理工具,简化开发体验。适合小程序等项目等的开发。

查看demo

快速上手

创建一个 module

const app = {
  namespace: 'app',
  state: {
    past: [],
    current: 0,
    future: []
  },
  actions: {}
}

添加 actions

const app = {
  namespace: 'app',
  state: {
    past: [],
    current: 0,
    future: []
  },
  actions: {
    change ({ setState }, val) {
      const newPast = [...this.state.past, this.state.current]
      setState({
        past: newPast,
        current: val
      })
    },
    undo ({ setState }) {
      const { past, future, current } = this.state
      if (past.length === 0) { return }
      
      const previous = past.pop()
      const newFuture = [current, ...future]
      setState({
        past: [...past],
        current: previous,
        future: newFuture
      })
    },
    redo ({ setState }) {
      const { past, future, current } = this.state
      if (future.length === 0) {
        return
      }
      const next = future.shift()
      const newPast = [...past, current]
      setState({
        past: newPast,
        current: next,
        future: [...future]
      })
    }
  }
}

创建 Store

const store = createStore({ modules: app })

获取对状态读取和修改的方法

const states = store.mapStates({
  val: 'app/current'
})

const actions = store.mapActions({
  change: 'app/change',
  add (dispatch) {
    dispatch('app/change', states.val + 1)
    render('app/change')
  },
  reduce (dispatch) {
    dispatch('app/change', states.val - 1)
    render('app/change')
  },
  undo (dispatch) {
    dispatch('app/undo')
    render('app/undo')
  },
  redo (dispatch) {
    dispatch('app/redo')
    render('app/redo')
  }
})

调用方法

actions.add()

Current Tags

  • 1.1.1                                ...           latest (3 months ago)

12 Versions

  • 1.1.1                                ...           3 months ago
  • 1.1.0                                ...           3 months ago
  • 1.0.6                                ...           4 months ago
  • 1.0.5                                ...           4 months ago
  • 1.0.4                                ...           4 months ago
  • 1.0.3                                ...           4 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.1                                ...           4 months ago
  • 1.0.0                                ...           4 months ago
  • 1.0.9                                ...           8 months ago
  • 1.0.8                                ...           8 months ago
  • 1.0.7                                ...           8 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 15
Dependencies (0)
None
Dev Dependencies (9)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |