Skip to content

Commit 323e338

Browse files
alOnehmysiar
authored andcommitted
Fix Vue.js generator (#38)
* Fix Vue.js generator * Update SubmissionError.js
1 parent e795fea commit 323e338

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

src/generators/VueCrudGenerator.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export default class VueCrudGenerator {
3434
// entrypoint
3535
this.registerTemplate(templatePath, 'config/_entrypoint.js');
3636

37+
// error
38+
this.registerTemplate(templatePath, 'error/SubmissionError.js');
39+
3740
// utils
3841
this.registerTemplate(templatePath, 'utils/fetch.js');
3942
}
@@ -55,18 +58,18 @@ import ${titleLc}Routes from './routes/${titleLc}';
5558
const router = new VueRouter({
5659
// ...
5760
routes: [
58-
...{ ${titleLc}Routes },
61+
...${titleLc}Routes,
5962
]
6063
});
6164
6265
// Add the modules in the store
6366
import { ${titleLc} from './store/modules/{ ${titleLc}/';
6467
6568
export const store = new Vuex.Store({
66-
// ...
67-
modules: {
68-
{ ${titleLc}
69-
}
69+
// ...
70+
modules: {
71+
${titleLc}
72+
}
7073
});
7174
`));
7275
}
@@ -90,6 +93,7 @@ export const store = new Vuex.Store({
9093
// Create directories
9194
// These directories may already exist
9295
mkdirp.sync(`${dir}/config`);
96+
mkdirp.sync(`${dir}/error`);
9397
mkdirp.sync(`${dir}/routes`);
9498
mkdirp.sync(`${dir}/utils`);
9599

@@ -115,6 +119,9 @@ export const store = new Vuex.Store({
115119
// config
116120
this.createFile('config/_entrypoint.js', `${dir}/config/_entrypoint.js`, context);
117121

122+
// error
123+
this.createFile('error/SubmissionError.js', `${dir}/error/SubmissionError.js`, context);
124+
118125
// routes
119126
this.createFile('routes/foo.js', `${dir}/routes/${lc}.js`, context);
120127
}

src/generators/VueCrudGenerator.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ test('Generate a Vue app', () => {
3737

3838
expect(fs.existsSync(tmpobj.name+'/config/_entrypoint.js'), true);
3939

40+
expect(fs.existsSync(tmpobj.name+'/error/SubmissionError.js'), true);
41+
4042
expect(fs.existsSync(tmpobj.name+'/store/modules/abc/create.js'), true);
4143
expect(fs.existsSync(tmpobj.name+'/store/modules/abc/delete.js'), true);
4244
expect(fs.existsSync(tmpobj.name+'/store/modules/abc/index.js'), true);

templates/vue/components/foo/List.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,18 @@
7575
</template>
7676

7777
<script>
78-
import { createNamespacedHelpers } from 'vuex';
79-
80-
const { mapActions, mapGetters } = createNamespacedHelpers('{{{lc}}}/list');
78+
import { mapActions, mapGetters } from 'vuex';
8179
8280
export default {
83-
computed: mapGetters([
84-
'items',
85-
'loading',
86-
'view'
87-
]),
81+
computed: mapGetters({
82+
deletedItem: '{{{lc}}}/del/deleted',
83+
error: '{{{lc}}}/list/error',
84+
items: '{{{lc}}}/list/items',
85+
loading: '{{{lc}}}/list/loading',
86+
view: '{{{lc}}}/list/view'
87+
}),
8888
methods: mapActions({
89-
getPage: 'getItems'
89+
getPage: '{{{lc}}}/list/getItems'
9090
}),
9191
created () {
9292
this.$store.dispatch('{{{lc}}}/list/getItems')
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default class SubmissionError extends Error {
2+
constructor(errors) {
3+
super('Submit Validation Failed');
4+
this.errors = errors;
5+
Error.captureStackTrace(this, this.constructor);
6+
this.name = this.constructor.name;
7+
return this;
8+
}
9+
}

templates/vue/store/modules/foo/list.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function view(items) {
3131
}
3232

3333
const getters = {
34+
error: state => state.error,
3435
items: state => state.items,
3536
loading: state => state.loading,
3637
view: state => state.view

0 commit comments

Comments
 (0)