
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
frint-model
Advanced tools
Model package for Frint
Use frint-data
instead.
With npm:
$ npm install --save frint-model
Via unpkg CDN:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.0.1/Rx.min.js"></script>
<script src="https://unpkg.com/frint-model@latest/dist/frint-model.min.js"></script>
<script>
// available as `window.FrintModel`
</script>
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.Let's import the necessary function from the library first:
import { createModel } from 'frint-model';
Now we can create our Model:
const Shirt = createModel({
getColor: function () {
return this.get('color');
},
getSize: function () {
return this.get('size');
},
});
Building a new model instance object:
const shirt = new Shirt({
color: 'blue',
size: 'medium',
});
const color = shirt.getColor(); // blue
const size = shirt.getSize(); // medium
The model instance can also be observed for changes:
shirt.get$().subscribe(function (shirtAttributes) {
// triggered when the model had any change
});
shirt.get$('color').subscribe(function (color) {
// triggered when the model's `color` key changes
});
Model
The base Model class. You can extend the base Model class freely to your own like.
import { Model } from 'frint-model';
export default class Shirt extends Model {
getColor() {
return this.get('color');
}
getSize() {
return this.get('size');
}
}
createModel(extend)
Creates and returns an ES6 compatible class. Useful in non-ES6 compatible environments.
extend
(Object
): An object with the functions to extend the base Model class with.Function
: ES6 compatible class.
const Shirt = createModel({
getColor: function () {
return this.get('color');
},
getSize: function () {
return this.get('size');
},
});
const model = new Model();
The Model
instance
model.get(key)
key
(String
): Can be dot separated, like deep.nested.path
. If empty, it returns all the attributes.Any
: The key's value.
model.set(key, value)
Sets the value
for given key
in the model.
key
(String
)value
(Any
)void
.
get$(key)
Streams the model for given key.
key
(String
)Observable
.
v3.1.1 (2017-10-06)
frint-compat
, frint-component-handlers
, frint-component-utils
, frint-config
, frint-data
, frint-model
, frint-react
, frint-router-component-handlers
, frint-router-react
, frint-router
, frint-store
, frint
FAQs
Model package for Frint
The npm package frint-model receives a total of 59 weekly downloads. As such, frint-model popularity was classified as not popular.
We found that frint-model demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.