Quick Start

Create a New KOS Model

Steps

Model Specification

Create a new file at src/models/demo/types/index.d.ts

  1. Create the model Options

// src/models/demo/types/index.d.ts

declare interface IDemoModelOptions {
  name: string;
}
  1. Create the model specification

// src/models/demo/types/index.d.ts

declare interface IDemoModel extends IDemoModelOptions, IKosDataModel {
  id: string;
}

Create the Model Factory

Create a new file at src/models/demo/demo-factory.ts

import { modelFactory } from "@coca-cola/kos-ui-core";
export const DEMO_TYPE = "demo";
export const DemoFactory = modelFactory<IDemoModel, {}>(DEMO_TYPE);

Create the Model Implementation

Create a new file at src/models/demo/demo-model.ts

import { kosModel } from "@coca-cola/kos-ui-core";
import { DemoFactory } from "./demo-factory";
import { getDemo } from "./services/demo-services";

import log from "loglevel";
import { kosAction } from "@coca-cola/kos-ui-components";

@kosModel<IDemoModel, IDemoModelOptions>(DemoFactory.type)
export class DemoModel implements IDemoModel {
  id: string;
  name: string;
  constructor(modelId: string, options: IDemoModelOptions) {
    // assign the id from the passed in model id
    this.id = modelId;
    this.name = options.name;
  }
  async init(): Promise<void> {
    log.info("initialized model");
  }

  /**
   * The load lifecycle method provides an opportunity to hydrate the model with data fetched
   * from the backend.
   */
  async load(): Promise<void> {
    log.info("loaded model");
  }
}

Register the new model

  1. Add the new model to the registry for the application at src/App.tsx.

// src/App.tsx

import { DemoFactory } from "./models/demo/demo-factory";
import { DemoModel } from "./models/demo/demo-model";

export const Registry: IKosRegistry = {
  models: {
    [DemoFactory.type]: {
      class: DemoModel,
    },
  },
  preloadModels: [],
};
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.