Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hooks/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default class extends EventEmitter {
document.addEventListener(eventName, function (e) {
for (let target = e.target; target && target !== this; target = target.parentNode) {
if (target.matches(elementSelector)) {
handler.call(target, e);
handler.call(target, e, target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we pass target 2 times now ?

Copy link
Contributor

@junedkazi junedkazi Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the first argument be elementSelector ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first param is for binding this context

break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class extends BaseHooks {
}

itemAdd() {
this.subscribe('submit', '[data-cart-item-add]', (event) => {
this.emit('cart-item-add', event, event.target);
this.subscribe('submit', '[data-cart-item-add]', (event, target) => {
this.emit('cart-item-add', event, target);
});
}
}
8 changes: 4 additions & 4 deletions src/hooks/faceted-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export default class extends BaseHooks {
}

searchEvents() {
this.subscribe('click', '[data-faceted-search-facet]', (event) => {
this.emit('facetedSearch-facet-clicked', event);
this.subscribe('click', '[data-faceted-search-facet]', (event, target) => {
this.emit('facetedSearch-facet-clicked', event, target);
});

this.subscribe('submit', '[data-faceted-search-range]', (event) => {
this.emit('facetedSearch-range-submitted', event);
this.subscribe('submit', '[data-faceted-search-range]', (event, target) => {
this.emit('facetedSearch-range-submitted', event, target);
});
}
}
4 changes: 2 additions & 2 deletions src/hooks/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class extends BaseHooks {
}

optionsChange() {
this.subscribe('change', '[data-product-option-change]', (event) => {
this.emit('product-option-change', event, event.target);
this.subscribe('change', '[data-product-option-change]', (event, target) => {
this.emit('product-option-change', event, target);
});
}
}
4 changes: 2 additions & 2 deletions src/hooks/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default class extends BaseHooks {
}

quickSearch() {
this.subscribe('input', '[data-search-quick]', (event) => {
this.emit('search-quick', event);
this.subscribe('input', '[data-search-quick]', (event, target) => {
this.emit('search-quick', event, target);
});
}
}
12 changes: 6 additions & 6 deletions src/hooks/sort-by.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ export default class extends BaseHooks {
}

sortByEvents() {
this.subscribe('submit', '[data-sort-by]', (event) => {
this.emit('sortBy-submitted', event);
this.subscribe('submit', '[data-sort-by]', (event, target) => {
this.emit('sortBy-submitted', event, target);
});

this.subscribe('change', '[data-sort-by] select', (event) => {
this.emit('sortBy-select-changed', event);
this.subscribe('change', '[data-sort-by] select', (event, target) => {
this.emit('sortBy-select-changed', event, target);

if (!event.isDefaultPrevented()) {
event.currentTarget.closest('form').submit();
if (!event.isDefaultPrevented) {
target.closest('form').submit();
}
});
}
Expand Down