Skip to content

Commit

Permalink
Merge pull request #21 from dhershman1/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
dhershman1 authored Feb 21, 2020
2 parents e01821d + 3287c22 commit 5268e7f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## v2.4.0

### New

- Added the `event` Object itself to the function call, it is passed as the 2nd parameter

## v2.3.0

### New
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ You can pass the time in multiple formats:
<input v-debounce:1s.unlock="myFunc" type="text" />
```

The value of the input is passed along to your function
The value of the input is passed along to your function as the first parameter, and the 2nd parameter is the event object itself.

## Overwriting Events

Expand All @@ -146,8 +146,9 @@ A full example:
<script>
export default {
methods: {
myFn(val) {
myFn(val, e) {
console.log(val) // => The value of the input
console.log(e) // => The event object
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/debounce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/vue-debounce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-debounce",
"version": "2.3.0",
"version": "2.4.0",
"description": "A simple vue directive for debounce",
"main": "dist/vue-debounce.min.js",
"types": "types/index.d.ts",
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ export default {
Vue.directive('debounce', {
bind (el, { value, arg, modifiers }) {
const listener = figureOutEvent(el.attributes, listenTo)
const fn = debounce(target => {
value(target.value)
const fn = debounce(e => {
value(e.target.value, e)
}, arg || defaultTime)

function handler ({ key, target }) {
function handler (event) {
const isUnlocked = (!modifiers.lock && !lock) || modifiers.unlock

if ((key === 'Enter' && isUnlocked) || (!target.value && fireOnEmpty)) {
if ((event.key === 'Enter' && isUnlocked) || (!event.target.value && fireOnEmpty)) {
fn.cancel()
value(target.value)
value(event.target.value, event)
}

if (key !== 'Enter') {
fn(target)
if (event.key !== 'Enter') {
fn(event)
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
new Vue({
el: '#app',
methods: {
foo (val) {
foo (val, e) {
console.log('FOOBAR')
console.log(val)
console.log(e)
},
testFn(val) {
return cbVal => {
Expand Down

0 comments on commit 5268e7f

Please sign in to comment.