Skip to content

Commit bd0e058

Browse files
committed
fix(MdRipple): improve ripple performance
1 parent d4e4277 commit bd0e058

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"dependencies": {
4141
"deepmerge": "^1.5.1",
4242
"popper.js": "^1.12.5",
43+
"raf": "^3.3.2",
4344
"vue": "^2.4.3"
4445
},
4546
"devDependencies": {

src/components/MdList/MdListItem/MdListItem.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import MdListItemExpand from './MdListItemExpand'
88
import MdButton from 'components/MdButton/MdButton'
99
10-
function resolveScopedSlot (hasExpand, children) {
11-
if (hasExpand) {
10+
function hasExpansion (props) {
11+
return props.hasOwnProperty('mdExpand') && props.mdExpand !== false
12+
}
13+
14+
function resolveScopedSlot (props, children) {
15+
if (hasExpansion(props)) {
1216
return {
1317
'md-expand': () => {
1418
return children['md-expand'][0]
@@ -23,9 +27,6 @@
2327
components: {
2428
MdButton
2529
},
26-
props: {
27-
mdExpand: Boolean
28-
},
2930
render (createElement, { parent, props, listeners, data, slots }) {
3031
const interactionEvents = [
3132
'click',
@@ -38,7 +39,7 @@
3839
let listComponent = MdListItemDefault
3940
let staticClass = 'md-list-item'
4041
41-
if (props.mdExpand) {
42+
if (hasExpansion(props)) {
4243
listComponent = MdListItemExpand
4344
} else if (parent && parent.$router && props.to) {
4445
listComponent = MdListItemRouter
@@ -68,7 +69,7 @@
6869
}, [
6970
createElement(listComponent, {
7071
props,
71-
scopedSlots: resolveScopedSlot(props.mdExpand, children),
72+
scopedSlots: resolveScopedSlot(props, children),
7273
staticClass: 'md-list-item-container md-button-clean'
7374
}, children.default)
7475
])

src/components/MdList/MdListItem/MdListItemExpand.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
</template>
1414

1515
<script>
16+
import raf from 'raf'
1617
import MdArrowDownIcon from 'core/icons/MdArrowDownIcon'
1718
import MdListItemMixin from './MdListItemMixin'
1819
@@ -45,7 +46,7 @@
4546
return size
4647
},
4748
toggleExpand () {
48-
window.requestAnimationFrame(() => {
49+
raf(() => {
4950
let fullHeight = 0
5051
5152
if (!this.showContent) {
@@ -56,6 +57,9 @@
5657
this.showContent = !this.showContent
5758
})
5859
}
60+
},
61+
created () {
62+
console.log(this.$slots)
5963
}
6064
}
6165
</script>

src/components/MdRipple/MdRipple.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
</template>
1515

1616
<script>
17+
import raf from 'raf'
1718
import MdComponent from 'core/MdComponent'
1819
1920
export default new MdComponent({
@@ -70,7 +71,7 @@
7071
}, 100)
7172
},
7273
startRipple ($event) {
73-
window.requestAnimationFrame(async () => {
74+
raf(async () => {
7475
const { eventType, isDisabled, mdCentered } = this
7576
7677
if (!isDisabled && (!eventType || eventType === $event.type)) {

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,6 +5350,12 @@ querystring@0.2.0, querystring@^0.2.0:
53505350
version "0.2.0"
53515351
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620"
53525352

5353+
raf@^3.3.2:
5354+
version "3.3.2"
5355+
resolved "https://registry.yarnpkg.com/raf/-/raf-3.3.2.tgz#0c13be0b5b49b46f76d6669248d527cf2b02fe27"
5356+
dependencies:
5357+
performance-now "^2.1.0"
5358+
53535359
randomatic@^1.1.3:
53545360
version "1.1.7"
53555361
resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c"

0 commit comments

Comments
 (0)