Skip to content

Commit 4fce3aa

Browse files
Merge branch 'feature/throttle-and-debounce' into develop
2 parents 539e459 + 484ef04 commit 4fce3aa

File tree

7 files changed

+47
-12
lines changed

7 files changed

+47
-12
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
VUE_APP_PACKAGE_JSON=''
33

44
# TAG must be corresponding with the version tag in package.json, need to modify it when new version releases
5-
TAG=1.1.0
5+
TAG=1.2.0-beta

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuetify-typescript-playground",
3-
"version": "1.1.0",
3+
"version": "1.2.0-beta",
44
"license": "Apache-2.0",
55
"description": "Vuetify Typescript Playground",
66
"author": {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-disable no-unused-vars */
2+
import { DirectiveOptions } from 'vue'
3+
import _ from 'lodash'
4+
5+
const debouncedClickDirectiveOptions: DirectiveOptions = {
6+
inserted (el, directiveBinding) {
7+
const wait: number = directiveBinding.arg ? +directiveBinding.arg : 1000
8+
el.addEventListener('click', _.debounce(event => {
9+
directiveBinding.value.call(el, event)
10+
}, wait))
11+
}
12+
}
13+
14+
export default debouncedClickDirectiveOptions
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Vue from 'vue'
2+
import debouncedClickDirectiveOptions from './debounced-click-directive-options'
3+
4+
Vue.directive('debounced-click', debouncedClickDirectiveOptions)

src/main.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ import vuetify from './plugins/vuetify'
66
import 'roboto-fontface/css/roboto/roboto-fontface.css'
77
import '@mdi/font/css/materialdesignicons.css'
88
import '@/directives/throttled-click'
9-
import { ColorSchemeUtil } from '@/utils/color-scheme-util'
9+
import '@/directives/debounced-click'
10+
import { listenToColorScheme } from '@/plugins/adaptive-color-scheme'
1011

1112
Vue.config.productionTip = false
1213

13-
const vue = new Vue({
14+
const vueInstance = new Vue({
1415
router,
1516
store,
1617
vuetify,
1718
render: h => h(App)
1819
}).$mount('#app')
1920

20-
const media = window.matchMedia('(prefers-color-scheme: dark)')
21-
media.addEventListener('change', () => {
22-
vue.$vuetify.theme.dark = ColorSchemeUtil.isDarkMode()
23-
})
21+
listenToColorScheme(vueInstance)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { ColorSchemeUtil } from '@/utils/color-scheme-util'
2+
// eslint-disable-next-line no-unused-vars
3+
import Vue from 'vue'
4+
5+
/**
6+
* Listen to color scheme
7+
* @param vueInstance Vue instance
8+
* @author Johnny Miller (鍾俊), e-mail: [email protected]
9+
* @date 12/31/19 7:43 AM
10+
*/
11+
export function listenToColorScheme (vueInstance: Vue): void {
12+
const media = window.matchMedia('(prefers-color-scheme: dark)')
13+
media.addEventListener('change', () => {
14+
vueInstance.$vuetify.theme.dark = ColorSchemeUtil.isDarkMode()
15+
})
16+
}

src/views/VuetifyDemo.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="vuetify-demo-container">
33
<h1 class="text-center">This is an about page</h1>
44
<v-container>
5-
<v-carousel cycle height="400" hide-delimiter-background show-arrows-on-hover>
5+
<v-carousel cycle height="400" hide-delimiter-background show-arrows-on-hover v-ripple>
66
<v-carousel-item v-for="(slide, i) in slides" :key="i">
77
<v-sheet :color="colors[i]" height="100%">
88
<v-row class="fill-height" align="center" justify="center">
@@ -39,8 +39,8 @@
3939
<v-list-item-avatar tile size="80" color="grey"/>
4040
</v-list-item>
4141
<v-card-actions>
42-
<v-btn text v-throttled-click:2000="handleThrottledClickButton">Button</v-btn>
43-
<v-btn text>Button</v-btn>
42+
<v-btn text v-throttled-click:2000="handleThrottledClickButton">Throttle</v-btn>
43+
<v-btn text v-debounced-click:2000="handleDebouncedClickButton">Debounce</v-btn>
4444
</v-card-actions>
4545
</v-card>
4646
<v-row align="center">
@@ -148,7 +148,10 @@ export default Vue.extend({
148148
},
149149
methods: {
150150
handleThrottledClickButton (event: Event) {
151-
console.log('handleThrottledClickButton', event)
151+
console.info('handleThrottledClickButton', event)
152+
},
153+
handleDebouncedClickButton (event: Event) {
154+
console.info('handleDebouncedClickButton', event)
152155
},
153156
onResize () {
154157
this.windowSize = { x: window.innerWidth, y: window.innerHeight }

0 commit comments

Comments
 (0)