Skip to content

Commit

Permalink
updated examples with latest vue, solve problem with login example no…
Browse files Browse the repository at this point in the history
…t starting up. and added vuex into call-log example
  • Loading branch information
lyonlai committed Jan 28, 2018
1 parent a82f134 commit c79a45c
Show file tree
Hide file tree
Showing 12 changed files with 779 additions and 320 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
dist/build.js
.DS_Store
.vscode
2 changes: 2 additions & 0 deletions examples/call-log/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Call log example.
This example is a [webpack2](https://webpack.github.io/) [vue-loader](https://github.com/vuejs/vue-loader) example. It appends logs after mount every second.

Example has been updated with VueX.

```
yarn install
yarn start
Expand Down
2 changes: 2 additions & 0 deletions examples/call-log/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'blessed-vue'
import LogComponent from './log.vue'
import store from './store'

const el = Vue.dom.createElement()

Expand All @@ -10,5 +11,6 @@ const instance = new Vue({
components: {
LogComponent
},
store,
template: '<LogComponent />'
}).$mount(el)
12 changes: 10 additions & 2 deletions examples/call-log/log.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
import moment from 'moment'
import faker from 'faker'
import prettySeconds from 'pretty-seconds'
import { mapActions, mapState } from 'vuex'
export default {
name: 'log-component',
computed: mapState({
logs: state => state.logs
}),
methods: mapActions([
'appendLog'
]),
data: () => {
return {
logs: '',
logStyle: {
bg: 'black',
fg: 'white',
Expand All @@ -27,8 +34,9 @@ export default {
this.$refs.screen.key(['C-c'], () => {
process.exit(0)
})
console.log(this.$store)
setInterval(() => {
this.logs = `${this.logs}\n\n${faker.name.findName()} called from ${faker.address.state()} ${prettySeconds(faker.random.number(3600))} ago.`
this.appendLog(`${faker.name.findName()} called from ${faker.address.state()} ${prettySeconds(faker.random.number(3600))} ago.`)
}, 1000)
}
}
Expand Down
9 changes: 5 additions & 4 deletions examples/call-log/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
"start": "npm run build && node bundle.js"
},
"devDependencies": {
"vue-loader": "^12.0.2",
"vue-template-compiler": "^2.3.0",
"vue-loader": "^13.7.0",
"vue-template-compiler": "^2.5.13",
"webpack": "^2.3.3",
"webpack-node-externals": "^1.5.4"
},
"dependencies": {
"blessed-vue": "^1.2.0",
"blessed-vue": "^2.0.0",
"faker": "^4.1.0",
"moment": "^2.18.1",
"pretty-seconds": "^0.2.1"
"pretty-seconds": "^0.2.1",
"vuex": "^3.0.1"
}
}
39 changes: 39 additions & 0 deletions examples/call-log/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import BlessedVue from 'blessed-vue'
import Vuex from 'vuex'

BlessedVue.use(Vuex)

// root state object.
// each Vuex instance is just a single state tree.
const state = {
logs: ''
}

// mutations are operations that actually mutates the state.
// each mutation handler gets the entire state tree as the
// first argument, followed by additional payload arguments.
// mutations must be synchronous and can be recorded by plugins
// for debugging purposes.
const mutations = {
appendLog (state, message) {
state.logs += `\n\n${message}`
}
}

// actions are functions that cause side effects and can involve
// asynchronous operations.
const actions = {
appendLog: ({ commit }, message) => commit('appendLog', message)
}

// getters are functions
const getters = {}

// A Vuex instance is created by combining the state, mutations, actions,
// and getters.
export default new Vuex.Store({
state,
getters,
actions,
mutations
})
Loading

0 comments on commit c79a45c

Please sign in to comment.