@@ -35,7 +35,7 @@ import "prismjs/themes/prism-tomorrow.css"; // import syntax highlighting styles
35
35
export default {
36
36
data () {
37
37
return {
38
- // code: `Your component boilerplate will be displayed here.`,
38
+ code: ` Your component boilerplate will be displayed here.` ,
39
39
lineNumbers: true ,
40
40
height: null ,
41
41
};
@@ -46,18 +46,18 @@ export default {
46
46
computed: {
47
47
// needs access to current component aka activeComponent
48
48
... mapState ([" componentMap" , " activeComponent" , " activeComponentObj" , " exportAsTypescript" ]),
49
- code : function () {
50
- let computedCode = " Your component boilerplate will be displayed here." ;
51
- if (this .activeComponent ) {
52
- computedCode = this .createCodeSnippet (
49
+ },
50
+ methods: {
51
+ snippetInvoke (){
52
+ if (this .activeComponent !== ' ' ){
53
+ this .code = this .createCodeSnippet (
53
54
this .componentMap [this .activeComponent ].componentName ,
54
55
this .componentMap [this .activeComponent ].children
55
- );
56
+ )
57
+ } else {
58
+ this .code = ' Your component boilerplate will be displayed here.'
56
59
}
57
- return computedCode;
58
60
},
59
- },
60
- methods: {
61
61
highlighter (myCode ) {
62
62
return highlight (myCode, languages .js );
63
63
},
@@ -161,16 +161,16 @@ export default {
161
161
// add import mapstate and mapactions if they exist
162
162
let imports = " " ;
163
163
if (
164
- this .activeComponentObj .actions .length ||
165
- this .activeComponentObj .state .length
164
+ this .componentMap [ this . activeComponent ] .actions .length ||
165
+ this .componentMap [ this . activeComponent ] .state .length
166
166
) {
167
167
imports += " import { " ;
168
168
if (
169
- this .activeComponentObj .actions .length &&
170
- this .activeComponentObj .state .length
169
+ this .componentMap [ this . activeComponent ] .actions .length &&
170
+ this .componentMap [ this . activeComponent ] .state .length
171
171
) {
172
172
imports += " mapState, mapActions" ;
173
- } else if (this .activeComponentObj .state .length ) imports += " mapState" ;
173
+ } else if (this .componentMap [ this . activeComponent ] .state .length ) imports += " mapState" ;
174
174
else imports += " mapActions" ;
175
175
imports += ' } from "vuex";\n ' ;
176
176
}
@@ -193,9 +193,9 @@ export default {
193
193
194
194
// if true add data section and populate with props
195
195
let data = " " ;
196
- if (this .activeComponentObj .props .length ) {
196
+ if (this .componentMap [ this . activeComponent ] .props .length ) {
197
197
data += " data () {\n return {" ;
198
- this .activeComponentObj .props .forEach ((prop ) => {
198
+ this .componentMap [ this . activeComponent ] .props .forEach ((prop ) => {
199
199
data += ` \n ${ prop} : "PLACEHOLDER FOR VALUE",` ;
200
200
});
201
201
data += " \n " ;
@@ -205,10 +205,10 @@ export default {
205
205
206
206
// if true add computed section and populate with state
207
207
let computed = " " ;
208
- if (this .activeComponentObj .state .length ) {
208
+ if (this .componentMap [ this . activeComponent ] .state .length ) {
209
209
computed += " computed: {" ;
210
210
computed += " \n ...mapState([" ;
211
- this .activeComponentObj .state .forEach ((state ) => {
211
+ this .componentMap [ this . activeComponent ] .state .forEach ((state ) => {
212
212
computed += ` \n "${ state} ",` ;
213
213
});
214
214
computed += " \n ]),\n " ;
@@ -217,10 +217,10 @@ export default {
217
217
218
218
// if true add methods section and populate with actions
219
219
let methods = " " ;
220
- if (this .activeComponentObj .actions .length ) {
220
+ if (this .componentMap [ this . activeComponent ] .actions .length ) {
221
221
methods += " methods: {" ;
222
222
methods += " \n ...mapActions([" ;
223
- this .activeComponentObj .actions .forEach ((action ) => {
223
+ this .componentMap [ this . activeComponent ] .actions .forEach ((action ) => {
224
224
methods += ` \n "${ action} ",` ;
225
225
});
226
226
methods += " \n ]),\n " ;
@@ -260,29 +260,25 @@ export default {
260
260
},
261
261
},
262
262
watch: {
263
- // // watches activeComponentObj for changes to make it reactive upon mutation
264
- // activeComponentObj: {
265
- // handler () {
266
- // // console.log(this.activeComponentObj.children)
267
- // this.code = this.createCodeSnippet(
268
- // this.activeComponentObj.componentName,
269
- // this.activeComponentObj.children
270
- // )
271
- // }
272
- // },
273
- // // // // watches componentMap for changes to make it reactive upon mutation
274
- // componentMap: {
275
- // handler () {
276
- // this.code = this.createCodeSnippet(
277
- // this.activeComponentObj.componentName,
278
- // this.activeComponentObj.children
279
- // )
280
- // }
281
- // }
263
+ // watches activeComponentObj for changes to make it reactive upon mutation
264
+ // // // watches componentMap for changes to make it reactive upon mutation
265
+ activeComponent: {
266
+ handler () {
267
+ this .snippetInvoke ();
268
+ },
269
+ deep: true
270
+ },
271
+ componentMap: {
272
+ handler () {
273
+ this .snippetInvoke ();
274
+ },
275
+ deep: true
276
+ }
282
277
},
283
278
mounted () {
284
279
// https://vuejs.org/v2/api/#Vue-nextTick
285
280
// kinda like a promise, used for the window resize
281
+ this .snippetInvoke ()
286
282
this .$nextTick (() => {
287
283
window .addEventListener (" resize" , this .getWindowHeight );
288
284
0 commit comments