Quick Start

Implement the Model Lifecycle

Create Data Access Service

// src/models/demo/services/demo-services.ts

import { ServiceFactory, resolveServiceUrl } from "@coca-cola/kos-ui-core";

const { URL } = resolveServiceUrl("DEMO_SERVICE");
const { getOne } = ServiceFactory.build({
  destinationAddress: "",
  basePath: `${URL}/foo`,
});

interface DemoResponse {
  id: string;
  name: string;
}
/**
 * @category Service
 * Retrieves a single demo model
 */
export const getDemo = async (id: string) => {
  const response = await getOne<DemoResponse>({
    urlOverride: `${URL}/foo/${id}`,
  });
  return response;
};

Implement the Load Lifecycle Hook

// src/models/demo/demo-model.ts

import {kosAction} from "@coca-cola/kos-ui-components";
import {getDemo} from "./services/demo-services";

    /**
     * The load lifecycle method provides an opportunity to hydrate the model with data fetched
     * from the backend.
     */
    async load(): Promise<void> {
        try {
            log.info("loading demo model");
            const response = await getDemo(this.id);
            log.debug(`received response ${response}`);
            kosAction(() => {
                const newName = response?.data.name;
                if (newName) {
                    this.name = newName;
                }
            });
        } catch(e) {
            log.error(e);
            throw e;
        }
    }
Previous
Next
On this page
Java Development
Seamlessly transition from Legacy+ systems to Freestyle microdosing and advanced distributed dispense systems.
UI Development
Using KOS SDKs, integrating Consumer and Non-consumer facing UIs becomes seamless, giving you less hassle and more time to create.
Video Library
Meet some of our development team, as they lead you through the tools, features, and tips and tricks of various KOS tools.
Resources
Familiarize yourself with KOS terminology, our reference materials, and explore additional resources that complement your KOS journey.
Copyright © 2024 TCCC. All rights reserved.