Skip to content

Commit

Permalink
Merge pull request #72 from dhershman1/development
Browse files Browse the repository at this point in the history
v3.1.1
  • Loading branch information
dhershman1 committed May 16, 2022
2 parents e1a7f18 + a8a4839 commit 5d7d5c0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## v3.1.1

### Fixed

- Erroring out when there were no attributes on your element tag [#71](https://github.com/dhershman1/vue-debounce/issues/71)
- Potential issue if passed events was just an empty array or string would cause debounce to stop listening all together
- This falls back on the value of `listenTo`

## v3.1.0

### Improved
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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": "3.1.0",
"version": "3.1.1",
"description": "A simple vue directive for debounce",
"main": "dist/vue-debounce.min.js",
"types": "types/index.d.ts",
Expand Down
12 changes: 7 additions & 5 deletions src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ function ensureArray (value) {

// Figures out the event we are using with the bound element
function mapOutListeningEvents (attrs, listenTo) {
// Make sure attributes exist on the element
const elEvents = attrs ? attrs['debounce-events'] : []
// If they set an events attribute that overwrites everything
if (attrs) {
if (elEvents && elEvents.length > 0) {
// Since they can send in an array or a string we need to be prepared for both
if (Array.isArray(attrs)) {
return toLowerMap(attrs)
if (Array.isArray(elEvents)) {
return toLowerMap(elEvents)
}
return toLowerMap(attrs.split(','))
return toLowerMap(elEvents.split(','))
}

return toLowerMap(ensureArray(listenTo))
Expand Down Expand Up @@ -81,7 +83,7 @@ export function getDirective (version = '2', {
fireonempty: fireOnEmpty,
cancelonempty: cancelOnEmpty
}, modifiers)
const events = mapOutListeningEvents(vnode.data.attrs['debounce-events'], listenTo)
const events = mapOutListeningEvents(vnode.data.attrs, listenTo)
const fn = debounce(e => {
debouncedFn(e.target.value, e)
}, timer)
Expand Down

0 comments on commit 5d7d5c0

Please sign in to comment.