Skip to content

Commit

Permalink
fix: change from CustomEvent to MessageEvent to be compatible with no…
Browse files Browse the repository at this point in the history
…dejs

- set set min node version to v15.0.0
  • Loading branch information
jembach committed Jul 5, 2022
1 parent b95c3e5 commit 1a4c540
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 16 deletions.
16 changes: 12 additions & 4 deletions packages/storefront-react/src/context.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
UserLoginEvent,
UserLogoutEvent,
UserSignupEvent,
CartRemoveItemEvent,
CartUpdateItemEvent,
} from '@makaira/storefront-types'
import React, { useEffect, useRef, useState } from 'react'
import { StorefrontReactCustomClient, StorefrontReactTypes } from './types'
Expand Down Expand Up @@ -109,8 +111,14 @@ const ShopProvider: React.FC<ShopProviderProps> = ({
// register shop event handlers to update internal state to be reactive
useEffect(() => {
client.addEventListener(CartAddItemEvent.eventName, reloadCartAfterUpdate)
client.addEventListener(CartAddItemEvent.eventName, reloadCartAfterUpdate)
client.addEventListener(CartAddItemEvent.eventName, reloadCartAfterUpdate)
client.addEventListener(
CartRemoveItemEvent.eventName,
reloadCartAfterUpdate
)
client.addEventListener(
CartUpdateItemEvent.eventName,
reloadCartAfterUpdate
)

client.addEventListener(UserSignupEvent.eventName, reloadUserAfterUpdate)
client.addEventListener(UserLoginEvent.eventName, reloadUserAfterUpdate)
Expand All @@ -122,11 +130,11 @@ const ShopProvider: React.FC<ShopProviderProps> = ({
reloadCartAfterUpdate
)
client.removeEventListener(
CartAddItemEvent.eventName,
CartRemoveItemEvent.eventName,
reloadCartAfterUpdate
)
client.removeEventListener(
CartAddItemEvent.eventName,
CartUpdateItemEvent.eventName,
reloadCartAfterUpdate
)

Expand Down
3 changes: 3 additions & 0 deletions packages/storefront-shop-adapter-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"files": [
"./dist"
],
"engines": {
"node": ">=15.0.0"
},
"scripts": {
"clean": "rimraf ./dist",
"lint:eslint": "eslint src --fix",
Expand Down
3 changes: 3 additions & 0 deletions packages/storefront-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"files": [
"./dist"
],
"engines": {
"node": ">=15.0.0"
},
"scripts": {
"clean": "rimraf ./dist",
"lint:eslint": "eslint src --fix",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MakairaAddItemToCartResData } from '../../providers'

export class CartAddItemEvent<
EventData extends MakairaAddItemToCartResData = MakairaAddItemToCartResData
> extends CustomEvent<EventData> {
> extends MessageEvent<EventData> {
static eventName = 'cart:add-item'
constructor(data: EventData) {
super(CartAddItemEvent.eventName, { detail: data })
super(CartAddItemEvent.eventName, { data })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MakairaAddItemToCartResData } from '../../providers'

export class CartRemoveItemEvent<
EventData extends MakairaAddItemToCartResData = MakairaAddItemToCartResData
> extends CustomEvent<EventData> {
> extends MessageEvent<EventData> {
static eventName = 'cart:remove-item'
constructor(data: EventData) {
super(CartRemoveItemEvent.eventName, { detail: data })
super(CartRemoveItemEvent.eventName, { data })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MakairaUpdateItemFromCartResData } from '../../providers'

export class CartUpdateItemEvent<
EventData extends MakairaUpdateItemFromCartResData = MakairaUpdateItemFromCartResData
> extends CustomEvent<EventData> {
> extends MessageEvent<EventData> {
static eventName = 'cart:update-item'
constructor(data: EventData) {
super(CartUpdateItemEvent.eventName, { detail: data })
super(CartUpdateItemEvent.eventName, { data })
}
}
4 changes: 2 additions & 2 deletions packages/storefront-types/src/events/user/login.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MakairaLoginResData } from '../../providers'

export class UserLoginEvent<
EventData extends MakairaLoginResData = MakairaLoginResData
> extends CustomEvent<EventData> {
> extends MessageEvent<EventData> {
static eventName = 'user:login'
constructor(data: EventData) {
super(UserLoginEvent.eventName, { detail: data })
super(UserLoginEvent.eventName, { data })
}
}
4 changes: 2 additions & 2 deletions packages/storefront-types/src/events/user/logout.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MakairaLogoutResData } from '../../providers'

export class UserLogoutEvent<
EventData extends MakairaLogoutResData = MakairaLogoutResData
> extends CustomEvent<EventData> {
> extends MessageEvent<EventData> {
static eventName = 'user:logout'
constructor(data: EventData) {
super(UserLogoutEvent.eventName, { detail: data })
super(UserLogoutEvent.eventName, { data })
}
}
4 changes: 2 additions & 2 deletions packages/storefront-types/src/events/user/signup.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { MakairaSignupResData } from '../../providers'

export class UserSignupEvent<
EventData extends MakairaSignupResData = MakairaSignupResData
> extends CustomEvent<EventData> {
> extends MessageEvent<EventData> {
static eventName = 'user:signup'
constructor(data: EventData) {
super(UserSignupEvent.eventName, { detail: data })
super(UserSignupEvent.eventName, { data })
}
}

0 comments on commit 1a4c540

Please sign in to comment.