
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
loopback-ds-computed-mixin
Advanced tools
A mixin for the LoopBack framework that adds computed properties to a model.
This is a mixin for the LoopBack framework that adds computed properties to a model.
A computed property is a property of which the value is set dynamically after reading model data from the data source.
loaded
observer.ctx.instance
.ctx.isNewInstance
.npm install --save loopback-ds-computed-mixin
Add the mixins property to your server/model-config.json:
{
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models"
],
"mixins": [
"loopback/common/mixins",
"../node_modules/loopback-ds-computed-mixin/lib",
"../common/mixins"
]
}
}
To use with your Models add the mixins
attribute to the definition object of your model config.
The property you want to compute has to be defined in the model. The callback can be a promise too.
{
"name": "Item",
"properties": {
"name": "String",
"description": "String",
"status": "String",
"readonly": "boolean"
},
"mixins": {
"Computed": {
"properties": {
"readonly": "computeReadonly"
}
}
}
}
On your model you have to define the callback method.
// Set an item to readonly if status is archived
Item.computeReadonly = function computeReadonly(item) {
return item.status === 'archived';
};
Run the tests in test.js
npm test
Run with debugging output on:
DEBUG='loopback:mixin:computed' npm test
FAQs
A mixin for the LoopBack framework that adds computed properties to a model.
We found that loopback-ds-computed-mixin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.