Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
update dependencies, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffan committed Jan 26, 2018
1 parent c6da545 commit 1643e73
Show file tree
Hide file tree
Showing 3 changed files with 442 additions and 704 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"karma-safari-launcher": "^1.0.0",
"karma-webpack": "^2.0.9",
"replace-in-file": "^3.1.0",
"rollup": "^0.52.3",
"rollup": "^0.55.1",
"rollup-plugin-buble": "^0.18.0",
"uglify-js": "^3.2.2",
"vue": "^2.5.13",
Expand Down
19 changes: 12 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function initEvents() {
if (events) {

forEach(events, (listeners, event) => {

forEach(isArray(listeners) ? listeners : [listeners], listener => {

var priority = 0;
Expand All @@ -36,19 +35,25 @@ function initEvents() {
listener = listener.handler;
}

if (typeof listener === 'string') {
const name = listener;
listener = (...args) => this[name].apply(this, args);
}

_events.push(Events.on(event, listener.bind(this), priority));
_events.push(Events.on(event, bindListener(listener, this), priority));
});
});

this.$on('hook:beforeDestroy', () => _events.forEach(off => off()));
}
}

function bindListener(fn, vm) {

if (typeof fn === 'string') {
return function () {
return vm[fn].apply(vm, arguments);
}
}

return fn.bind(vm);
}

if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(Events);
}
Expand Down
Loading

0 comments on commit 1643e73

Please sign in to comment.