STB SDK base model implementation
Represents domain-specific data or information that an application will be working with. A typical example is a user account (e.g name, avatar, e-mail) or a music track (e.g title, year, album). Holds information, but don’t handle behaviour and don’t format information or influence how data appears.
Installation
npm install stb-model
Usage
Add the constructor to the scope:
var Model = ;
Create an empty instance:
var model = ;
Create an instance with some data:
var model = attr1: value1 attr2: value2;
Clear all data:
modelclear;
emits
clear
event in case some data is present
Clear and set new model data:
model;
can emit
clear
andinit
events
Check an attribute existence:
if model ...
Get a model attribute value by name:
var value = model;
Update or create a model attribute:
var operationStatus = model;
emits
change
event withprev
field in data in case of update operation
Delete the given attribute by name:
var operationStatus = model;
emits
change
event
Performance notes
It is highly advisable to access a model data directly in case no events are required.
So instead of
var value = model;model;
to avoid performance penalty it's better to use
var value = modeldataattr1;modeldataattr5 = 'value5';
Debug mode
There is a global var
DEBUG
which activates additional consistency checks and protection logic not available in release mode.
In debug mode the constructor is exposed to the global namespace as window.Model
.
Contribution
If you have any problem or suggestion please open an issue here. Pull requests are welcomed with respect to the JavaScript Code Style.
License
stb-model
is released under the GPL-3.0 License.