StructureJS

0.15.2

A class based utility library for building modular and scalable web platform applications. Features opt-in classes and utilities which provide a solid foundation and toolset to build your next project.

BaseModel Class

Extends BaseObject
Module: model
Parent Module: StructureJS

Base Model is a design pattern used to transfer data between software application subsystems.

Note: If the data doesn't match the property names you can set the value manually after update super method has been called. Also in the class you inherit BaseModel from you can override the update method to handle the data how you want.

Index

Show:

Properties

Properties

IS_BASE_MODEL Boolean public static

This property helps distinguish a BaseModel from other functions.

sjsId Int public

The sjsId (StructureJS ID) is a unique identifier automatically assigned to most StructureJS objects upon instantiation.

Default: null

sjsOptions IBaseModelOptions public

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Constructor

BaseModel
(
  • [data]
  • [opts]
)

Parameters:

  • [data] Any optional

    Provide a way to update the base model upon initialization.

  • [opts] expand:boolean optional

    } Options for the base model.

Example:

// Example how to extend the BaseModel class.
let data = {
        make: 'Tesla',
        model: 'Model S',
        YeAr: 2014,
        feature: {
            abs: true,
            airbags: true
        }
}
let carModel = new CarModel(data);


// Example how to extend the BaseModel class.
class CarModel extends BaseModel {

    // You need to have properties so the data will get assigned.
    // If not the data will not get assigned to the model.
    make = null;
    model = null;
    year = null;
    allWheel = false; // Set a default value

    // You can assign BaseModel to a property which will
    // automatically created it and pass the data to it.
    feature = FeatureModel

    // If you have an array of data and want them assign to a BaseModel.
    feature = [FeatureModel];

    constructor(data = {}, opts = {}) {
        super(opts);

        if (data) {
            this.update(data);
        }
    }

    // @overridden BaseModel.update
    update(data) {
        super.update(data);

        // If the data doesn't match the property name.
        // You can set the value(s) manually after the update super method has been called.
        this.year = data.YeAr;
    }
}

Methods

_updateData
(
  • propertyData
  • updateData
)
protected

Parameters:

_updatePropertyWithDataPassedIn
(
  • propertyName
  • updateData
)
protected

Adds the updateData to the property

Parameters:

clone () BaseModel public

Create a clone/copy of the Base Model.

Returns:

Example:

const clone = carModel.clone();

destroy () Void public

The purpose of the destroy method is to make an object ready for garbage collection. This should be thought of as a one way function. Once destroy is called no further methods should be called on the object or properties accessed. It is the responsibility of those who implement this function to stop all running Timers, all running Sounds, and take any other steps necessary to make an object eligible for garbage collection.

By default the destroy method will null out all properties of the class automatically. You should call destroy on other objects before calling the super.

Returns:

Void:

Example:

destroy() {
     this.disable();

     this._childInstance.destroy();

     super.destroy();
}

fromJSON
(
  • json
)
public

Converts the string json data into an Object and calls the update method with the converted Object.

Parameters:

Example:

 const str = '{"make":"Tesla","model":"Model S","year":2014}'
 const carModel = new CarModel();
 carModel.fromJSON(str);

getQualifiedClassName () String public

Returns the fully qualified class name of an object.

Returns:

String:

Returns the class name.

Example:

let someClass = new SomeClass();
someClass.getQualifiedClassName();

// SomeClass

toJSON () Any public

Converts the Base Model data into a JSON object and deletes the sjsId property.

Returns:

Any:

Example:

const obj = carModel.toJSON();

toJSONString () String public

Converts a Base Model to a JSON string,

Returns:

Example:

const str = carModel.toJSONString();

update
(
  • [data]
)
public

Provide a way to update the Base Model.

Parameters:

  • [data] Object optional

    {any}

Example:

// Example of updating some of the data:
carModel.update({ year: 2015, allWheel: true});

// Of course you can also do it the following way:
carModel.year = 2015;
carModel.allWheel = false;

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index