-
-
Save FlorianRappl/55e7c443463ec5c09d49cbd2a3cb521f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
import { PiletApi } from "app-shell"; | |
import { BuyButton } from "./BuyButton"; | |
import { BasketInfo } from "./BasketInfo"; | |
interface BasketInfoExtension {} | |
interface BuyButtonExtension { | |
item: string; | |
} | |
export function setup(app: PiletApi) { | |
const connectBasket = app.createState({ | |
state: { | |
items: [] | |
}, | |
actions: { | |
addToCart(dispatch, item: string) { | |
dispatch(state => ({ | |
...state, | |
items: [...state.items, item] | |
})); | |
} | |
} | |
}); | |
app.registerExtension<BuyButtonExtension>( | |
"buy-button", | |
connectBasket(({ actions, params }) => ( | |
<BuyButton addToCart={actions.addToCart} item={params.item} /> | |
)) | |
); | |
app.registerExtension<BasketInfoExtension>( | |
"basket-info", | |
connectBasket(({ state }) => <BasketInfo count={state.items.length} />) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment