Render

Render html with data from the api.
Keeps the UI in sync with the data.

Usage

import { render } from 'geta-checkout';
render(selector, template);
render.init(apiOptions);

Render a built-in component

<div data-add-to-cart='{"itemId": "1"}'></div>
import { render, AddToCartUI } from 'geta-checkout';
render('[data-add-to-cart]', AddToCartUI);

Render a string

<div data-counter></div>
import { render } from 'geta-checkout';
render('[data-counter]', function(props) {
    return props.cart.totalQuantity + ' items in cart';
});

Render an ES6 template string

<div data-counter></div>
import { render } from 'geta-checkout';
const template = ({cart}) => `${cart.totalQuantity} items in cart`;
render('[data-counter]', template);

Render a custom React component

<div data-react-component></div>
import React from 'react';
import { render } from 'geta-checkout';
import ReactComponent from './my-react-component';
render('[data-react-component]', ReactComponent);

Configure API endpoints

Call render.init and pass in the apis.
This will render the UI with initial data from the server (or the build-in mock server).

import { render, mockServer, CartApi, CustomerApi, LanguageApi, PaymentApi, ShipmentApi } from 'geta-checkout';

const cartApi = new CartApi(server.cartServices);
const customerApi = new CustomerApi(server.customerServices);
const languageApi = new LanguageApi();
const paymentApi = new PaymentApi(server.paymentServices);
const shipmentApi = new ShipmentApi(server.shipmentServices);

render.init({
    cartApi: cartApi,
    customerApi: customerApi,
    languageApi: languageApi,
    paymentApi: paymentApi,
    shipmentApi: shipmentApi
});

cartApi.get();
customerApi.get();
languageApi.get();
paymentApi.get();
shipmentApi.get();