Skip to content

Commit 0f893b8

Browse files
Merge pull request #17 from ziggrace/sean/snippet
made code snippet reactive
2 parents 61538f5 + 5b6818c commit 0f893b8

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

src/components/dashboard_items/CodeSnippet.vue

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ export default {
4040
},
4141
computed: {
4242
// needs access to current component aka activeComponent
43-
...mapState(['componentMap', 'activeComponent', 'activeComponentObj'])
43+
...mapState(['componentMap', 'activeComponent', 'activeComponentObj']),
44+
activeObj (){
45+
return this.activeComponentObj
46+
}
4447
},
4548
methods: {
4649
getWindowHeight (e) {
@@ -137,12 +140,12 @@ export default {
137140
138141
// add import mapstate and mapactions if they exist
139142
let imports = ''
140-
if (this.activeComponentObj.actions.length || this.activeComponentObj.state.length){
143+
if (this.activeObj.actions.length || this.activeObj.state.length){
141144
imports += 'import { '
142-
if (this.activeComponentObj.actions.length && this.activeComponentObj.state.length) {
145+
if (this.activeObj.actions.length && this.activeObj.state.length) {
143146
imports += 'mapState, mapActions'
144147
}
145-
else if (this.activeComponentObj.state.length) imports += 'mapState'
148+
else if (this.activeObj.state.length) imports += 'mapState'
146149
else imports += 'mapActions'
147150
imports += ' } from "vuex"\n'
148151
}
@@ -160,9 +163,9 @@ export default {
160163
161164
// if true add data section and populate with props
162165
let data = ''
163-
if (this.activeComponentObj.props.length){
166+
if (this.activeObj.props.length){
164167
data += ' data () {\n return {'
165-
this.activeComponentObj.props.forEach(prop => {
168+
this.activeObj.props.forEach(prop => {
166169
data += `\n ${prop}: "PLACEHOLDER FOR VALUE",`
167170
})
168171
data += '\n'
@@ -172,10 +175,10 @@ export default {
172175
173176
// if true add computed section and populate with state
174177
let computed = ''
175-
if (this.activeComponentObj.state.length){
178+
if (this.activeObj.state.length){
176179
computed += ' computed: {'
177180
computed += '\n ...mapState(['
178-
this.activeComponentObj.state.forEach((state) =>{
181+
this.activeObj.state.forEach((state) =>{
179182
computed += `\n "${state}",`
180183
})
181184
computed += '\n ]),\n'
@@ -184,10 +187,10 @@ export default {
184187
185188
// if true add methods section and populate with actions
186189
let methods = ''
187-
if (this.activeComponentObj.actions.length){
190+
if (this.activeObj.actions.length){
188191
methods += ' methods: {'
189192
methods += '\n ...mapActions(['
190-
this.activeComponentObj.actions.forEach((action) => {
193+
this.activeObj.actions.forEach((action) => {
191194
methods += `\n "${action}",`
192195
})
193196
methods += '\n ]),\n'
@@ -213,6 +216,14 @@ export default {
213216
return output
214217
}
215218
},
219+
watch: {
220+
// watches activeComponentObj for changes to make it reactive upon mutation
221+
activeComponentObj: {
222+
handler(){
223+
this.code = this.createCodeSnippet(this.activeComponentObj.componentName, this.activeComponentObj.children)
224+
}
225+
}
226+
},
216227
mounted () {
217228
// https://vuejs.org/v2/api/#Vue-nextTick
218229
// kinda like a promise, used for the window resize

src/components/home_sidebar_items/ComponentList.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Description:
6565
</q-item>
6666
</q-list>
6767
</a>
68-
</br>
68+
<br/>
6969
<p>Toggle to edit actions</p>
7070
<toggle-button v-model="showActions" />
7171
<a

0 commit comments

Comments
 (0)