StructureJS
0.15.2A 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.
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.
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
BaseModel
[data]
[opts]
[data]
Any
optional
Provide a way to update the base model upon initialization.
[opts]
expand:boolean
optional
} Options for the base model.
// 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;
}
}
_updatePropertyWithDataPassedIn
propertyName
updateData
clone
()
BaseModel
public
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.
destroy() {
this.disable();
this._childInstance.destroy();
super.destroy();
}
fromJSON
json
getQualifiedClassName
()
String
public
Returns the fully qualified class name of an object.
Returns the class name.
let someClass = new SomeClass();
someClass.getQualifiedClassName();
// SomeClass
toJSON
()
Any
public
Converts the Base Model data into a JSON object and deletes the sjsId property.
const obj = carModel.toJSON();
toJSONString
()
String
public
Converts a Base Model to a JSON string,
const str = carModel.toJSONString();
update
[data]
Provide a way to update the Base Model.
[data]
Object
optional
{any}
// 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;