decorator with a custom container property name.
Use this interface when you specify a custom containerProperty in the decorator options
to get proper type safety for the custom property name.
// Specify the custom property name "devices" in both the interface and decorator
interface DeviceManagerImpl extends KosContainerAwareWithProp<DeviceModel, "devices"> {}
@kosModel("device-manager")
@kosContainerAware<DeviceModel>({ containerProperty: "devices" })
class DeviceManagerImpl implements IKosDataModel {
constructor(modelId: string, options: ContainerOptions, context: KosCreationContext) {
this.id = modelId;
}
addDevice(device: DeviceModel): void {
// Access container via custom property name
this.devices.addModel(device);
}
getDeviceCount(): number {
// The 'data' property is still available
return this.data.length;
}
}
// Custom property for user management
interface UserManagerImpl extends KosContainerAwareWithProp<UserModel, "users"> {}
@kosContainerAware<UserModel>({
containerProperty: "users",
containerOptions: {
indexMap: {
byRole: "role"
}
}
})
class UserManagerImpl implements IKosDataModel {
getUsersByRole(role: string): UserModel[] {
// Access via this.users instead of this.container
return this.users.getIndexByKey("byRole", role);
}
}
Interface for models using