Skip to content

Commit f61a2a3

Browse files
committed
perf(QFab/QFabAction): simplify communication between components quasarframework#7389 quasarframework#7393
1 parent 31f3d7d commit f61a2a3

File tree

3 files changed

+19
-68
lines changed

3 files changed

+19
-68
lines changed

ui/dev/src/pages/components/fab-extended.vue

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,6 @@
2020
Row {{ i }}
2121
</div>
2222

23-
<q-page-sticky position="bottom-left" :offset="[16, 16]">
24-
<q-fab-action
25-
class="white shadow-8"
26-
color="red"
27-
icon="center_focus_weak"
28-
label="Anchor start"
29-
:label-position="fabLabelPosition"
30-
:square="fabSquare"
31-
:hide-label="hideLabel"
32-
:label-class="labelClass"
33-
aria-label="Does nothing"
34-
/>
35-
</q-page-sticky>
36-
3723
<q-page-sticky :position="stickyConfig.position" :offset="stickyConfig.offset">
3824
<q-fab
3925
class="shadow-4"

ui/src/components/fab/QFab.js

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,7 @@ export default Vue.extend({
2222

2323
provide () {
2424
return {
25-
__qFabClose: evt => {
26-
this.hide(evt)
27-
28-
if (this.$refs.trigger && this.$refs.trigger.$el) {
29-
this.$refs.trigger.$el.focus()
30-
}
31-
},
32-
33-
__qFabRegister: fabAction => {
34-
if (this.fabActions.indexOf(fabAction) === -1) {
35-
this.fabActions.push(fabAction)
36-
fabAction.showing = this.showing
37-
}
38-
},
39-
40-
__qFabUnregister: fabAction => {
41-
const index = this.fabActions.indexOf(fabAction)
42-
if (index > -1) {
43-
this.fabActions.splice(index, 1)
44-
}
45-
}
25+
__qFab: this
4626
}
4727
},
4828

@@ -95,16 +75,14 @@ export default Vue.extend({
9575
}
9676
},
9777

98-
watch: {
99-
showing (val) {
100-
this.fabActions.forEach(fabAction => {
101-
fabAction.showing !== val && (fabAction.showing = val)
102-
})
103-
}
104-
},
78+
methods: {
79+
__onChildClick (evt) {
80+
this.hide(evt)
10581

106-
created () {
107-
this.fabActions = []
82+
if (this.$refs.trigger && this.$refs.trigger.$el) {
83+
this.$refs.trigger.$el.focus()
84+
}
85+
}
10886
},
10987

11088
render (h) {

ui/src/components/fab/QFabAction.js

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ const anchorMap = {
1515

1616
const anchorValues = Object.keys(anchorMap)
1717

18-
const defaultInjectRet = () => { }
19-
const defaultInject = () => defaultInjectRet
20-
2118
export default Vue.extend({
2219
name: 'QFabAction',
2320

@@ -34,21 +31,15 @@ export default Vue.extend({
3431
validator: v => anchorValues.includes(v)
3532
},
3633

37-
to: [String, Object],
34+
to: [ String, Object ],
3835
replace: Boolean
3936
},
4037

4138
inject: {
42-
__qFabClose: { default: defaultInject },
43-
44-
__qFabRegister: { default: defaultInject },
45-
46-
__qFabUnregister: { default: defaultInject }
47-
},
48-
49-
data () {
50-
return {
51-
showing: true
39+
__qFab: {
40+
default () {
41+
console.error('QFabAction needs to be child of QFab')
42+
}
5243
}
5344
},
5445

@@ -63,24 +54,20 @@ export default Vue.extend({
6354
...this.qListeners,
6455
click: this.click
6556
}
57+
},
58+
59+
isDisabled () {
60+
return this.__qFab.showing !== true || this.disable === true
6661
}
6762
},
6863

6964
methods: {
7065
click (e) {
71-
this.__qFabClose()
66+
this.__qFab.__onChildClick(e)
7267
this.$emit('click', e)
7368
}
7469
},
7570

76-
beforeMount () {
77-
this.__qFabRegister(this)
78-
},
79-
80-
beforeDestroy () {
81-
this.__qFabUnregister(this)
82-
},
83-
8471
render (h) {
8572
const child = []
8673

@@ -104,7 +91,7 @@ export default Vue.extend({
10491
label: void 0,
10592
noCaps: true,
10693
fabMini: true,
107-
disable: this.showing !== true || this.disable === true
94+
disable: this.isDisabled
10895
},
10996
on: this.onEvents
11097
}, mergeSlot(child, this, 'default'))

0 commit comments

Comments
 (0)