@@ -35,7 +35,7 @@ import "prismjs/themes/prism-tomorrow.css"; // import syntax highlighting styles
3535export default {
3636 data () {
3737 return {
38- // code: `Your component boilerplate will be displayed here.`,
38+ code: ` Your component boilerplate will be displayed here.` ,
3939 lineNumbers: true ,
4040 height: null ,
4141 };
@@ -46,18 +46,18 @@ export default {
4646 computed: {
4747 // needs access to current component aka activeComponent
4848 ... 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 (
5354 this .componentMap [this .activeComponent ].componentName ,
5455 this .componentMap [this .activeComponent ].children
55- );
56+ )
57+ } else {
58+ this .code = ' Your component boilerplate will be displayed here.'
5659 }
57- return computedCode;
5860 },
59- },
60- methods: {
6161 highlighter (myCode ) {
6262 return highlight (myCode, languages .js );
6363 },
@@ -161,16 +161,16 @@ export default {
161161 // add import mapstate and mapactions if they exist
162162 let imports = " " ;
163163 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
166166 ) {
167167 imports += " import { " ;
168168 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
171171 ) {
172172 imports += " mapState, mapActions" ;
173- } else if (this .activeComponentObj .state .length ) imports += " mapState" ;
173+ } else if (this .componentMap [ this . activeComponent ] .state .length ) imports += " mapState" ;
174174 else imports += " mapActions" ;
175175 imports += ' } from "vuex";\n ' ;
176176 }
@@ -193,9 +193,9 @@ export default {
193193
194194 // if true add data section and populate with props
195195 let data = " " ;
196- if (this .activeComponentObj .props .length ) {
196+ if (this .componentMap [ this . activeComponent ] .props .length ) {
197197 data += " data () {\n return {" ;
198- this .activeComponentObj .props .forEach ((prop ) => {
198+ this .componentMap [ this . activeComponent ] .props .forEach ((prop ) => {
199199 data += ` \n ${ prop} : "PLACEHOLDER FOR VALUE",` ;
200200 });
201201 data += " \n " ;
@@ -205,10 +205,10 @@ export default {
205205
206206 // if true add computed section and populate with state
207207 let computed = " " ;
208- if (this .activeComponentObj .state .length ) {
208+ if (this .componentMap [ this . activeComponent ] .state .length ) {
209209 computed += " computed: {" ;
210210 computed += " \n ...mapState([" ;
211- this .activeComponentObj .state .forEach ((state ) => {
211+ this .componentMap [ this . activeComponent ] .state .forEach ((state ) => {
212212 computed += ` \n "${ state} ",` ;
213213 });
214214 computed += " \n ]),\n " ;
@@ -217,10 +217,10 @@ export default {
217217
218218 // if true add methods section and populate with actions
219219 let methods = " " ;
220- if (this .activeComponentObj .actions .length ) {
220+ if (this .componentMap [ this . activeComponent ] .actions .length ) {
221221 methods += " methods: {" ;
222222 methods += " \n ...mapActions([" ;
223- this .activeComponentObj .actions .forEach ((action ) => {
223+ this .componentMap [ this . activeComponent ] .actions .forEach ((action ) => {
224224 methods += ` \n "${ action} ",` ;
225225 });
226226 methods += " \n ]),\n " ;
@@ -260,29 +260,25 @@ export default {
260260 },
261261 },
262262 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+ }
282277 },
283278 mounted () {
284279 // https://vuejs.org/v2/api/#Vue-nextTick
285280 // kinda like a promise, used for the window resize
281+ this .snippetInvoke ()
286282 this .$nextTick (() => {
287283 window .addEventListener (" resize" , this .getWindowHeight );
288284
0 commit comments