Skip to content

Commit

Permalink
Bug Fix: off unexpectedly removes unlocked handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaotoshiFujita committed Oct 7, 2021
1 parent 874a1ea commit 81fdec6
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/js/splide-renderer.min.js

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

4 changes: 2 additions & 2 deletions dist/js/splide.cjs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Splide.js
* Version : 3.0.8
* Version : 3.0.9
* License : MIT
* Copyright: 2021 Naotoshi Fujita
*/
Expand Down Expand Up @@ -332,7 +332,7 @@ function EventBus() {
forEachEvent(events, (event, namespace) => {
const eventHandlers = handlers[event];
handlers[event] = eventHandlers && eventHandlers.filter((handler) => {
return handler._key ? handler._key !== key : handler._namespace !== namespace;
return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js/splide.esm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* Splide.js
* Version : 3.0.8
* Version : 3.0.9
* License : MIT
* Copyright: 2021 Naotoshi Fujita
*/
Expand Down Expand Up @@ -328,7 +328,7 @@ function EventBus() {
forEachEvent(events, (event, namespace) => {
const eventHandlers = handlers[event];
handlers[event] = eventHandlers && eventHandlers.filter((handler) => {
return handler._key ? handler._key !== key : handler._namespace !== namespace;
return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
});
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/js/splide.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/js/splide.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/js/splide.min.js

Large diffs are not rendered by default.

Binary file modified dist/js/splide.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splidejs/splide",
"version": "3.0.8",
"version": "3.0.9",
"description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
"author": "Naotoshi Fujita",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/js/constructors/EventBus/EventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function EventBus(): EventBusObject {
const eventHandlers = handlers[ event ];

handlers[ event ] = eventHandlers && eventHandlers.filter( handler => {
return handler._key ? handler._key !== key : handler._namespace !== namespace;
return handler._key ? handler._key !== key : key || handler._namespace !== namespace;
} );
} );
}
Expand Down
20 changes: 20 additions & 0 deletions src/js/constructors/EventBus/test/key.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,24 @@ describe( 'EventBus', () => {
expect( onMounted ).not.toHaveBeenCalled();
expect( onMoved ).not.toHaveBeenCalled();
} );

test( 'should not remove a handler if a key does not match.', () => {
const event = EventBus();
const callback1 = jest.fn();
const callback2 = jest.fn();
const callback3 = jest.fn();
const key = {};

event.on( 'mounted', callback1 );
event.on( 'mounted', callback2, key );
event.on( 'mounted', callback3, key );

event.off( 'mounted', key );

event.emit( 'mounted' );

expect( callback1 ).toHaveBeenCalledTimes( 1 );
expect( callback2 ).not.toHaveBeenCalled()
expect( callback3 ).not.toHaveBeenCalled()
} );
} );

0 comments on commit 81fdec6

Please sign in to comment.