Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to dispatch custom events to the document object #14

Merged
merged 1 commit into from
Jan 11, 2023

Conversation

marcomontalbano
Copy link
Member

@marcomontalbano marcomontalbano commented Jan 11, 2023

With this PR, Commerce Layer drop-in.js will be able to dispatch the following custom events to the document object.

All custom events implement the same interface; request.args and response vary from one event to another.

interface CLCustomEvent {
  request: {
    args: [ arg1: any, arg2: any, ... ]
  }
  response: any
}

Event types

cl.cart.addItem

This event is dispatched when an item is added to cart.

  • request.args [sku: string, quantity: number]
  • response LineItem
document.addEventListener('cl.cart.addItem', (event) => {
  console.info(event.detail)
})

cl.prices.getPrice

This event is dispatched whenever a price is fetched.

  • request.args [code: string]
  • response Price
document.addEventListener('cl.prices.getPrice', (event) => {
  console.info(event.detail)
})

cl.skus.getSku

This event is dispatched whenever a SKU is fetched.

  • request.args [code: string]
  • response Sku
document.addEventListener('cl.skus.getSku', (event) => {
  console.info(event.detail)
})
cl-customevent.mp4

@marcomontalbano marcomontalbano added the enhancement New feature or request label Jan 11, 2023
@marcomontalbano marcomontalbano merged commit 734e323 into main Jan 11, 2023
@marcomontalbano marcomontalbano deleted the events branch January 11, 2023 17:16
@marcomontalbano marcomontalbano added this to the v1.1.0 milestone Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant