frint-model
Model package for Frint
WARNING: This package has been deprecated!
Use frint-data
instead.
Guide
Installation
With npm:
$ npm install --save frint-model
Via unpkg CDN:
Terminologies
Model
: An object that holds data, e.g. configuration, customer information, etc.attributes
: The actual data in plain object, which is fed to the Model during construction.
Usage
Let's import the necessary function from the library first:
;
Now we can create our Model:
const Shirt = ;
Building a new model instance object:
const shirt = color: 'blue' size: 'medium'; const color = shirt; // blueconst size = shirt; // medium
The model instance can also be observed for changes:
shirt; shirt;
API
Model
Model
The base Model class. You can extend the base Model class freely to your own like.
Example
; { return this; } { return this; }
createModel
createModel(extend)
Creates and returns an ES6 compatible class. Useful in non-ES6 compatible environments.
Arguments
extend
(Object
): An object with the functions to extend the base Model class with.
Returns
Function
: ES6 compatible class.
Example
const Shirt = ;
model
const model = new Model();
The Model
instance
model.get
model.get(key)
Arguments
key
(String
): Can be dot separated, likedeep.nested.path
. If empty, it returns all the attributes.
Returns
Any
: The key's value.
model.set
model.set(key, value)
Sets the value
for given key
in the model.
Arguments
key
(String
)value
(Any
)
Returns
void
.
get$
get$(key)
Streams the model for given key.
Arguments
key
(String
)
Returns
Observable
.