File

src/services/model/modelItems/userMI.ts

Description

A ModelItem that holds a AAAIUser.

Extends

ModelItem

Index

Properties
Methods

Constructor

constructor()

Properties

Public defaultValueSetter
Type : function
Inherited from ModelItem
Defined in ModelItem:78

The defaultValueSetter property is a function that takes a ModelItem object as a parameter and returns a promise that resolves to a value of type T. It is used to set the default value of the ModelItem. When the ModelItem is initialized, if the value is not populated from persistence, the defaultValueSetter function is called to set the default value of the ModelItem. The function can perform any necessary logic to determine the default value and return it as a promise.

Public identifier
Type : string
Inherited from ModelItem
Defined in ModelItem:38

The public identifier: string; line is declaring a public property identifier of type string in the ModelItem class. This property is used to uniquely identify the model item within the model. It can be used to retrieve or set the value of the model item using its identifier.

Public initFunction
Type : function
Inherited from ModelItem
Defined in ModelItem:83

The above code is defining a public property called initFunction which is a function that takes a parameter modelItem of type ModelItem<T>. The function returns a Promise that resolves to void.

Public initialised
Default value : false
Inherited from ModelItem
Defined in ModelItem:44

The line public initialised = false; is declaring a public property initialised with a default value of false. This property is used to track whether the ModelItem has been initialized or not. It is initially set to false and can be updated to true once the init method is called on the ModelItem.

Public isModelItem
Default value : true
Inherited from ModelItem
Defined in ModelItem:33

The line public isModelItem = true; // identifies this as a modalItem when type unknown is declaring a public property isModelItem with a default value of true. This property is used to identify an instance of the ModelItem class when its type is unknown. It can be used to check if an object is an instance of ModelItem even if its type information is not available.

Protected logging
Default value : false
Inherited from ModelItem
Defined in ModelItem:106

The above code is defining a class in TypeScript with a protected property called "logging" that is set to false.

Protected persistable
Default value : false
Inherited from ModelItem
Defined in ModelItem:97

The above code is declaring a protected property named "persistable" and assigning it a value of false.

Public persistableOnConfigurables
Default value : false
Inherited from ModelItem
Defined in ModelItem:57

The line public persistableOnConfigurables = false; is declaring a public property persistableOnConfigurables with a default value of false in the ModelItem class. This property is used to determine whether the model item should be persisted on configurable variables. If set to true, the model item's value will be persisted when the configurable variables are saved. If set to false, the model item's value will not be persisted on configurable variables.

Protected persister
Type : null | Persister
Inherited from ModelItem
Defined in ModelItem:93

The above code is declaring a protected property called "persister" with a type of either null or Persister.

Public populatedOnInit
Default value : false
Inherited from ModelItem
Defined in ModelItem:50

The line public populatedOnInit = false; is declaring a public property populatedOnInit with a default value of false. This property is used to track whether the ModelItem has been populated with a value during initialization or not. It is initially set to false and can be updated to true once the populateValueOnInit method is called on the ModelItem.

Public postPersistConverter
Type : function
Inherited from ModelItem
Defined in ModelItem:71

The postPersistConverter property is a function that takes a ModelItem object and a value of type unknown as parameters and returns a promise that resolves to a value of type T. It is used as a converter function to transform the value retrieved from persistence before it is set as the value of the ModelItem. This allows for custom logic to be applied to the retrieved value before it is used.

Public prePersistConverter
Type : function
Inherited from ModelItem
Defined in ModelItem:64

The line public prePersistConverter: (modelItem: ModelItem<T>) => unknown; is declaring a public property prePersistConverter in the ModelItem class. This property is a function that takes a ModelItem object as a parameter and returns a value of type unknown. It is used as a converter function to transform the value of the ModelItem before persisting it. This allows for custom logic to be applied to the value before it is stored in a persister.

Protected services
Type : Record<string | >
Inherited from ModelItem
Defined in ModelItem:102

The above code is declaring a protected property called "services" of type "Record<string, unknown>". The "services" property is an object that can hold key-value pairs, where the keys are strings and the values can be of any type.

Public valueObs
Type : Observable<T>
Inherited from ModelItem
Defined in ModelItem:86

The above code is declaring a public variable called valueObs of type Observable<T>.

Protected valueSource
Type : BehaviorSubject<T>
Inherited from ModelItem
Defined in ModelItem:89

The above code is declaring a protected variable called valueSource of type BehaviorSubject<T>.

Methods

Public get
get()
Inherited from ModelItem
Defined in ModelItem:303
Returns : T

Current Value

Public getContext
getContext()
Inherited from ModelItem
Defined in ModelItem:343

The getContext function returns the context associated with a given identifier in the modelContext array.

Returns : string

a string value.

Public getModel
getModel()
Inherited from ModelItem
Defined in ModelItem:319
Returns : Model

The Model that this item is registered to.

Protected getPersistedValue
getPersistedValue()
Inherited from ModelItem
Defined in ModelItem:374

The function getPersistedValue returns a promise that resolves to the persisted value of a model item, if available.

Returns : Promise<>

A Promise that resolves to an unknown value.

Public getService
getService(service: string)
Inherited from ModelItem
Defined in ModelItem:330

The function getService retrieves a service based on its id and returns it, or logs an error if the service is not set. service that you want to retrieve from the services object.

Parameters :
Name Type Optional Description
service string No
  • The service parameter is a string that represents the id of the service that you want to retrieve from the services object.
Public init
init(services: Record)
Inherited from ModelItem
Defined in ModelItem:157

The init function initializes the object with the provided services and executes an optional initialization function before marking the object as initialized. unknown values. It is used to store various services or dependencies that the class or function may need to access or use.

Parameters :
Name Type Optional Description
services Record<string | > No
  • The services parameter is a record (or dictionary) that maps string keys to unknown values. It is used to store various services or dependencies that the class or function may need to access or use.
Returns : void
Protected log
log(message?: string, ...optionalParams: Array<>)
Inherited from ModelItem
Defined in ModelItem:362

The log function logs a message and optional parameters if logging is enabled. meaning it can be omitted when calling the function. its elements.

Parameters :
Name Type Optional Description
message string Yes
  • A string representing the log message. It is an optional parameter, meaning it can be omitted when calling the function.
optionalParams Array<> No
  • An array of unknown type, which means it can accept any type of values as its elements.
Returns : void
Static make
make(defaultValue: T1)
Inherited from ModelItem
Defined in ModelItem:146
Type parameters :
  • T1

The function "make" creates a new instance of the ModelItem class with a specified default value. to the ModelItem object. It is of type T1, which means it can be any type specified when calling the make method. defaultValue as its constructor argument.

Parameters :
Name Type Optional Description
defaultValue T1 No
  • The defaultValue parameter is the initial value that will be assigned to the ModelItem object. It is of type T1, which means it can be any type specified when calling the make method.
Returns : ModelItem<T1>

The method is returning an instance of the ModelItem<T1> class with the specified defaultValue as its constructor argument.

Static makeNullable
makeNullable(defaultValue: null | T1)
Inherited from ModelItem
Defined in ModelItem:134
Type parameters :
  • T1

The function "makeNullable" returns a new instance of "ModelItem" with a default value that can be null or of type T1. that allows you to specify a default value for the ModelItem. It has a type of null | T1, which means it can either be null or of type T1. If no value is provided for defaultValue, it null | T1, where T1 is a type parameter. The constructor of ModelItem is being called with the defaultValue parameter as an argument.

Parameters :
Name Type Optional Default value Description
defaultValue null | T1 No null
  • The defaultValue parameter is an optional parameter that allows you to specify a default value for the ModelItem. It has a type of null | T1, which means it can either be null or of type T1. If no value is provided for defaultValue, it

The method is returning a new instance of the ModelItem class with a generic type of null | T1, where T1 is a type parameter. The constructor of ModelItem is being called with the defaultValue parameter as an argument.

Public populateValueOnInit
populateValueOnInit()
Inherited from ModelItem
Defined in ModelItem:266

The function "populateValueOnInit" checks if a model item exists, sets its value from persistence, sets a default value if necessary, and marks it as populated on initialization.

Public set
set(value: T, force)
Inherited from ModelItem
Defined in ModelItem:283

Sets the value

Parameters :
Name Type Optional Default value Description
value T No

New value.

force No false

Forces change notifications even if old and new values were the same.

Returns : void
Public setDefaultValueFunction
setDefaultValueFunction(defaultValueSetter: (modelItem: ModelItem) => void)
Inherited from ModelItem
Defined in ModelItem:207

The function sets a default value for a model item using a provided callback function. modelItem of type ModelItem<T> and returns a Promise of type T. It is used to set the default value for the modelItem.

Parameters :
Name Type Optional Description
defaultValueSetter function No
  • The defaultValueSetter parameter is a function that takes a modelItem of type ModelItem<T> and returns a Promise of type T. It is used to set the default value for the modelItem.
Protected setFromDefault
setFromDefault()
Inherited from ModelItem
Defined in ModelItem:424

The function setFromDefault sets the value of a model item from its default value, if available.

Returns : Promise<void>

The function setFromDefault() returns a Promise that resolves to void.

Protected setFromPersistence
setFromPersistence()
Inherited from ModelItem
Defined in ModelItem:394

The function setFromPersistence retrieves a persisted value, converts it if necessary, and sets it on the model item.

Returns : Promise<void>

a Promise that resolves to void (undefined).

Public setIdentifier
setIdentifier(id: string)
Inherited from ModelItem
Defined in ModelItem:233

The function sets the identifier property of an object and returns the object itself.

Parameters :
Name Type Optional Description
id string No
  • The "id" parameter is a string that represents the identifier value.
Public setInitFunction
setInitFunction(initFunc: (modelItem: ModelItem) => void)
Inherited from ModelItem
Defined in ModelItem:221

The setInitFunction method sets the initialization function for a model item and returns the instance of the class. argument and returns a Promise that resolves to void.

Parameters :
Name Type Optional Description
initFunc function No
  • The initFunc parameter is a function that takes a modelItem of type T as an argument and returns a Promise that resolves to void.
Private setInitialised
setInitialised(initialised)
Inherited from ModelItem
Defined in ModelItem:443

The function sets the value of the "initialised" property to true by default, but can also accept a different value. an object or variable has been initialized or not.

Parameters :
Name Optional Default value Description
initialised No true
  • The "initialised" parameter is a boolean value that indicates whether an object or variable has been initialized or not.
Returns : void
Public setPersistable
setPersistable(persistable)
Inherited from ModelItem
Defined in ModelItem:175

The function sets the persistable property of an object and returns the object itself. an object should be persisted or not. If set to true, the object will be saved and stored for future use. If set to false, the object will not be persisted and will not be saved for future use.

Parameters :
Name Optional Default value Description
persistable No true
  • The "persistable" parameter is a boolean value that determines whether an object should be persisted or not. If set to true, the object will be saved and stored for future use. If set to false, the object will not be persisted and will not be saved for future use.
Public setPersistableOnConfigurables
setPersistableOnConfigurables(value: boolean)
Inherited from ModelItem
Defined in ModelItem:245

The function sets the value of the "persistableOnConfigurables" property and returns the instance of the class. on configurables.

Parameters :
Name Type Optional Description
value boolean No
  • A boolean value that determines whether the object should be persistable on configurables.
Public setPersister
setPersister(persister: null | Persister)
Inherited from ModelItem
Defined in ModelItem:256

The function sets the persister property of an object and returns the object itself. It is used to set the persister for the current object.

Parameters :
Name Type Optional Description
persister null | Persister No
  • The persister parameter is of type null or Persister. It is used to set the persister for the current object.
Public setPersistFunctions
setPersistFunctions(prePersistConverter, postPersistConverter)
Inherited from ModelItem
Defined in ModelItem:190

The function sets pre-persist and post-persist converters for a model item. ModelItem and converts it to an unknown type. It is used before persisting the modelItem. modelItem and value. It is used to convert the persisted value back to its original type T. The modelItem parameter represents the ModelItem object that was persisted, and the value parameter represents the persisted value. The function should return a Promise

Parameters :
Name Optional Default value Description
prePersistConverter No (modelItem: ModelItem<T>) => modelItem.get() as unknown
  • The prePersistConverter is a function that takes a modelItem of type ModelItem and converts it to an unknown type. It is used before persisting the modelItem.
postPersistConverter No (modelItem: ModelItem<T>, value: unknown) => Promise.resolve(value as T)
  • The postPersistConverter is a function that takes two parameters: modelItem and value. It is used to convert the persisted value back to its original type T. The modelItem parameter represents the ModelItem object that was persisted, and the value parameter represents the persisted value. The function should return a Promise
Public trigger
trigger()
Inherited from ModelItem
Defined in ModelItem:311

Results in the emitting of a notifications of change, but with the same value as before.

Returns : void
import { ModelItem } from './modelItem';
import { AAAIUser } from 'api/aaai/aaaiUser.interface';
import { AaaiService } from 'api/aaai.service';

/**
 * A {@link ModelItem} that holds a {@link AAAIUser}.
 */
export class UserMI extends ModelItem<null | AAAIUser> {

  constructor(
  ) {
    super(null);

    this.setInitFunction((modelItem: ModelItem<AAAIUser>) => {
      return new Promise((resolve) => {
        const aaaiService = this.getService('AaaiService') as AaaiService;
        // set current
        this.set(aaaiService.getUser());
        // on init, set up a watch
        aaaiService.watchUser().subscribe((aaaiUser: null | AAAIUser) => {
          if (aaaiUser !== this.get()) {
            this.set(aaaiUser);
          }
        });
        resolve();
      });
    });
  }
}

results matching ""

    No results matching ""