Skip to content

Commit

Permalink
feat: [doc] 完善 asyncData 例子
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Aug 22, 2019
1 parent 7b1a386 commit 54439aa
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 541 deletions.
2 changes: 1 addition & 1 deletion doc/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"modules": false,
"targets": {
"chrome": "58",
"ie": "9"
"ie": "11"
}
}
]
Expand Down
33 changes: 10 additions & 23 deletions doc/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Store } from 'vuex'
import { TMutations as GlobalMutations } from 'src/store/mutations'
import { TActions as GlobalActions } from 'src/store/actions'
import { TMutations as EditorMutations } from 'src/store/editor/mutations'
import { TActions as EditorActions } from 'src/store/editor/actions'

/**
* Doc 全局类型
Expand Down Expand Up @@ -56,10 +58,15 @@ declare namespace Doc {

/**
* 编辑器
* - 模块
*/
editor?: {
test: string
deepTest: {
/**
* 深层编辑器
* - 模块
*/
deepTest?: {
test1: string
test2: number
}
Expand Down Expand Up @@ -138,17 +145,7 @@ declare namespace Doc {
/**
* 编辑器
*/
editor: GlobalMutations & {
/**
* 编辑器
*/
editor2: GlobalMutations & {
/**
* 编辑器
*/
editor3: GlobalMutations
}
}
editor: EditorMutations
}

/**
Expand All @@ -158,17 +155,7 @@ declare namespace Doc {
/**
* 编辑器
*/
editor: GlobalActions & {
/**
* 编辑器
*/
editor2: GlobalActions & {
/**
* 编辑器
*/
editor3: GlobalActions
}
}
editor: EditorActions
}
}

Expand Down
3 changes: 2 additions & 1 deletion doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"src"
],
"dependencies": {
"@bestminr/build": "^1.6.22",
"@bestminr/build": "^1.6.23",
"@bestminr/vuex-utils": "^0.2.1-alpha.0",
"axios": "^0.17.0",
"cross-env": "^4.0.0",
"lodash": "^4.17.15",
Expand Down
21 changes: 21 additions & 0 deletions doc/src/store/editor/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { VUEX_NS, editorHelper as helper, commit } from './index'
import { Tstore } from '@types'

export const actions = helper.makeActions({
TEST_ACTION(ctx, { id, version }: { id: number } & Pick<Tstore.state, 'version'>) {
let resove
const promise = new Promise((res) => resove = res)
setTimeout(() => {
console.log('timeout!')
commit(ctx, 'TEST_VERSION', { version })
resove()
}, 1000)
return promise
}
})

export default actions

export type TActions = typeof actions

export const dispatch = helper.createDispatch<Tstore.Actions[VUEX_NS]>()
2 changes: 2 additions & 0 deletions doc/src/store/editor/getters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default {
}
22 changes: 20 additions & 2 deletions doc/src/store/editor/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
export const VUEX_NS = 'editor'
export type VUEX_NS = typeof VUEX_NS
export * from './type'

import Vue from 'vue'
import Vuex from 'vuex'
import actions, { dispatch } from './actions'
import mutations, { commit, getState } from './mutations'
import getters from './getters'
import state from './state'

Vue.use(Vuex)

export default {
namespaced: true,
state: state(),
actions,
mutations,
getters,
}

export { commit, getState, dispatch }
15 changes: 15 additions & 0 deletions doc/src/store/editor/mutations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { VUEX_NS, editorHelper as helper } from './index'
import { Tstore } from '@types'

export const mutations = helper.makeMutations({
TEST_VERSION: (state, { version }: Pick<Tstore.state, 'version'>) => {
state.test = version
},
})

export default mutations

export type TMutations = typeof mutations

export const commit = helper.createCommit<Tstore.Mutations[VUEX_NS]>()
export const getState = helper.createGetState()
7 changes: 7 additions & 0 deletions doc/src/store/editor/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Tstore } from '@types'

export default function state(): Tstore.state['editor'] {
return {
test: 'vuex 初始化 string'
}
}
7 changes: 7 additions & 0 deletions doc/src/store/editor/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Tstore } from '@types'
import { makeWrapper } from 'src/store/helpers'

export const VUEX_NS = 'editor'
export type VUEX_NS = typeof VUEX_NS

export const editorHelper = makeWrapper<Tstore.state[VUEX_NS], Tstore.getters[VUEX_NS]>(VUEX_NS)
8 changes: 2 additions & 6 deletions doc/src/store/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Tstore } from '@types'
import { VuexStoreHelper } from 'src/store/utils'
import { VuexStoreHelper } from '@bestminr/vuex-utils'

import { VUEX_NS as editor } from 'src/store/editor'

const { makeWrapper } = new VuexStoreHelper<Tstore.state, Tstore.getters>()
export const { makeWrapper } = new VuexStoreHelper<Tstore.state, Tstore.getters>()

export const globalHelper = makeWrapper()
export const editorHelper = makeWrapper<Tstore.state[editor], Tstore.getters[editor]>(editor)

/**
* 例子 1
*/
Expand Down
Loading

0 comments on commit 54439aa

Please sign in to comment.