mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
Vuex (#8041)
* add vuex, cleanup client directory and create example components * disale sample unit test * disable import for non existing file * correct regexp for unit tests, add simple test to avoid error, add babel-polyfill for Vuex * add line wrongly removed, update regexp
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
# Compiled and vendored files
|
# Compiled and vendored files
|
||||||
common/dist/
|
|
||||||
common/transpiled-babel/
|
|
||||||
coverage/
|
coverage/
|
||||||
database_reports/
|
database_reports/
|
||||||
website/build/
|
website/build/
|
||||||
website/transpiled-babel/
|
website/transpiled-babel/
|
||||||
|
website/common/transpiled-babel/
|
||||||
dist/
|
dist/
|
||||||
|
|
||||||
# Not linted
|
# Not linted
|
||||||
|
|||||||
@@ -96,6 +96,8 @@
|
|||||||
"vinyl-source-stream": "^1.1.0",
|
"vinyl-source-stream": "^1.1.0",
|
||||||
"vue": "^2.0.0-rc.6",
|
"vue": "^2.0.0-rc.6",
|
||||||
"vue-router": "^2.0.0-rc.5",
|
"vue-router": "^2.0.0-rc.5",
|
||||||
|
"vuex": "^2.0.0-rc.5",
|
||||||
|
"vuex-router-sync": "^3.0.0",
|
||||||
"winston": "^2.1.0",
|
"winston": "^2.1.0",
|
||||||
"xml2js": "^0.4.4"
|
"xml2js": "^0.4.4"
|
||||||
},
|
},
|
||||||
@@ -135,7 +137,6 @@
|
|||||||
"babel-core": "^6.0.0",
|
"babel-core": "^6.0.0",
|
||||||
"babel-eslint": "^6.0.0",
|
"babel-eslint": "^6.0.0",
|
||||||
"babel-loader": "^6.0.0",
|
"babel-loader": "^6.0.0",
|
||||||
"babel-plugin-transform-runtime": "^6.0.0",
|
|
||||||
"chai": "^3.4.0",
|
"chai": "^3.4.0",
|
||||||
"chai-as-promised": "^5.1.0",
|
"chai-as-promised": "^5.1.0",
|
||||||
"chalk": "^1.1.3",
|
"chalk": "^1.1.3",
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
|
// TODO verify if it's needed, added because Vuex require Promise in the global scope
|
||||||
|
// and babel-runtime doesn't affect external libraries
|
||||||
|
require('babel-polyfill');
|
||||||
|
|
||||||
// require all test files (files that ends with .spec.js)
|
// require all test files (files that ends with .spec.js)
|
||||||
var testsContext = require.context('./specs', true, /\.spec$/);
|
var testsContext = require.context('./specs', true, /\.spec$/);
|
||||||
testsContext.keys().forEach(testsContext);
|
testsContext.keys().forEach(testsContext);
|
||||||
|
|
||||||
// require all src files except main.js/ README.md / index.html for coverage.
|
// require all src files except main.js/ README.md / index.html for coverage.
|
||||||
var srcContext = require.context('../../../website/client', true, /^\.\/(?!(main\.js|README\.md|index\.html)?$)/);
|
var srcContext = require.context('../../../website/client', true, /^\.\/(?!(main(\.js)?)|(index(\.html)?)$)/);
|
||||||
srcContext.keys().forEach(srcContext);
|
srcContext.keys().forEach(srcContext);
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Hello from 'src/components/Hello';
|
// import Hello from 'src/components/Hello';
|
||||||
|
|
||||||
describe('Hello.vue', () => {
|
describe('Hello.vue', () => {
|
||||||
it('should render correct contents', () => {
|
xit('should render correct contents', () => {
|
||||||
const vm = new Vue({
|
const vm = new Vue({
|
||||||
el: document.createElement('div'),
|
el: document.createElement('div'),
|
||||||
render: (h) => h(Hello),
|
render: (h) => h(Hello),
|
||||||
});
|
});
|
||||||
expect(vm.$el.querySelector('.hello h1').textContent).to.equal('Hello Vue!');
|
expect(vm.$el.querySelector('.hello h1').textContent).to.equal('Hello Vue!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should make assertions', () => {
|
||||||
|
expect(true).to.equal(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
3
website/README.md
Normal file
3
website/README.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
`/website/client` contains the source files for the new client side that is being developed as part of the Habitica.com redesign.
|
||||||
|
|
||||||
|
The old client side files can be found in `/website/client-old`, they are still used on Habitica.com while the redesign is in progress.
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"presets": ["es2015"],
|
"presets": ["es2015"],
|
||||||
"plugins": ["transform-runtime"],
|
|
||||||
"comments": false
|
"comments": false
|
||||||
}
|
}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
This folder contains the source files for the new client side that is being developed.
|
|
||||||
|
|
||||||
The old client side files can be found in /website/client-old, they are still used on Habitica.com while the redesign is in progress.
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 6.7 KiB |
@@ -1,64 +1,30 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
#app
|
#app
|
||||||
img.logo(src='../assets/logo.png')
|
site-header
|
||||||
ul
|
ul
|
||||||
li
|
li
|
||||||
router-link(to='/') Home
|
router-link(to='/') Home
|
||||||
li
|
li
|
||||||
router-link(to='/sub') Sub
|
router-link(to='/page') Another Page
|
||||||
router-view.view
|
router-view.view
|
||||||
p Welcome to your Vue.js app!
|
|
||||||
p
|
|
||||||
| To get a better understanding of how this boilerplate works, check out
|
|
||||||
| <a href="http://vuejs-templates.github.io/webpack" target="_blank">its documentation</a>.
|
|
||||||
| It is also recommended to go through the docs for
|
|
||||||
| <a href="http://webpack.github.io/" target="_blank">Webpack</a> and
|
|
||||||
| <a href="http://vuejs.github.io/vue-loader/" target="_blank">vue-loader</a>.
|
|
||||||
| If you have any issues with the setup, please file an issue at this boilerplate's
|
|
||||||
| <a href="https://github.com/vuejs-templates/webpack" target="_blank">repository</a>.
|
|
||||||
p
|
|
||||||
| You may also want to checkout
|
|
||||||
| <a href="https://github.com/vuejs/vue-router/" target="_blank">vue-router</a> for routing and
|
|
||||||
| <a href="https://github.com/vuejs/vuex/" target="_blank">vuex</a> for state management.
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Hello from './Hello';
|
import SiteHeader from './siteHeader';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
Hello,
|
SiteHeader,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
html {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
#app {
|
||||||
color: #2c3e50;
|
margin: 0 auto;
|
||||||
margin-top: -100px;
|
width: 80%;
|
||||||
max-width: 600px;
|
border-left : 1px solid;
|
||||||
font-family: Source Sans Pro, Helvetica, sans-serif;
|
border-right: 1px solid;
|
||||||
text-align: center;
|
padding: 20px;
|
||||||
}
|
|
||||||
|
|
||||||
#app a {
|
|
||||||
color: #42b983;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
width: 100px;
|
|
||||||
height: 100px
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
.hello
|
|
||||||
h1 {{ msg }}
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
msg: 'Hello Sub Route!',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
||||||
<style scoped>
|
|
||||||
h1 {
|
|
||||||
color: #42b983;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
30
website/client/components/app.vue
Normal file
30
website/client/components/app.vue
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
#app
|
||||||
|
site-header
|
||||||
|
ul
|
||||||
|
li
|
||||||
|
router-link(to='/') Home
|
||||||
|
li
|
||||||
|
router-link(to='/page') Another Page
|
||||||
|
router-view.view
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import SiteHeader from './siteHeader';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
SiteHeader,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
#app {
|
||||||
|
margin: 0 auto;
|
||||||
|
width: 80%;
|
||||||
|
border-left : 1px solid;
|
||||||
|
border-right: 1px solid;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
13
website/client/components/home.vue
Normal file
13
website/client/components/home.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
p {{ msg }}
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
msg: 'You\'re on the Home page!',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
13
website/client/components/page.vue
Normal file
13
website/client/components/page.vue
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
p {{ msg }}
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
msg: 'You\'re on Another Page!',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.hello
|
h1 {{ title }}
|
||||||
h1 {{ msg }}
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState } from 'vuex';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data () {
|
computed: mapState([
|
||||||
return {
|
'title',
|
||||||
msg: 'Hello Vue!',
|
]),
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -1,9 +1,19 @@
|
|||||||
|
// TODO verify if it's needed, added because Vuex require Promise in the global scope
|
||||||
|
// and babel-runtime doesn't affect external libraries
|
||||||
|
require('babel-polyfill');
|
||||||
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import App from './components/App';
|
import VuexRouterSync from 'vuex-router-sync';
|
||||||
|
import App from './components/app';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
|
import store from './vuex/store';
|
||||||
|
|
||||||
|
// Sync Vuex and Router
|
||||||
|
VuexRouterSync.sync(store, router);
|
||||||
|
|
||||||
new Vue({ // eslint-disable-line no-new
|
new Vue({ // eslint-disable-line no-new
|
||||||
router,
|
router,
|
||||||
|
store,
|
||||||
el: '#app',
|
el: '#app',
|
||||||
render: h => h(App),
|
render: h => h(App),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import VueRouter from 'vue-router';
|
import VueRouter from 'vue-router';
|
||||||
import Hello from './components/Hello';
|
import Home from './components/home';
|
||||||
import Sub from './components/Sub';
|
import Page from './components/page';
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ export default new VueRouter({
|
|||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: __dirname,
|
base: __dirname,
|
||||||
routes: [
|
routes: [
|
||||||
{ path: '/', component: Hello },
|
{ path: '/', component: Home },
|
||||||
{ path: '/sub', component: Sub },
|
{ path: '/page', component: Page },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
12
website/client/vuex/store.js
Normal file
12
website/client/vuex/store.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import Vue from 'vue';
|
||||||
|
import Vuex from 'vuex';
|
||||||
|
|
||||||
|
Vue.use(Vuex);
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
title: 'Habitica',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default new Vuex.Store({
|
||||||
|
state,
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user