Events
Fired when the swapping session ends.
When the user drops the item, even after multiple swaps, Swapy fires an event for that called swapEnd.
You can listen to that event using swapy.onSwapEnd()
.
swapy.onSwapEnd((event) => {
console.log(event)
})
The event object contains the following:
slotItemMap
: the new slot-to-item map after all swaps.
asArray
, asObject
, and asMap
.hasChanged
: a boolean indicating whether the slot-to-item map changed after all the swaps.
hasChanged
will be false.swapy.onSwapEnd((event) => {
console.log(event.slotItemMap.asObject)
// {
// 'foo': 'a',
// 'bar': 'b',
// 'baz': 'c'
// }
console.log(event.slotItemMap.asArray)
// [
// { slot: 'foo', item: 'a' },
// { slot: 'bar', item: 'b' },
// { slot: 'baz', item: 'c' }
// ]
console.log(event.slotItemMap.asMap)
// Map(3) {
// 'foo' => 'a',
// 'bar' => 'b',
// 'baz' => 'c'
// }
console.log(event.hasChanged)
// false
})
To see this event in action, use the demo below, open the dev console, and check the event object logged when the swapping session ends.