Exciting news!Announcing our $4.6M Series Seed. Learn more
Socket
LoveBlogFAQ
Install
Log in

loopback-ds-computed-mixin

Package Overview
Dependencies
3
Maintainers
3
Versions
11
Issues
File Explorer

Advanced tools

loopback-ds-computed-mixin

A mixin for the LoopBack framework that adds computed properties to a model.

    2.0.4latest

Version published
Maintainers
3
Yearly downloads
15,042
increased by11.22%

Weekly downloads

Changelog

Source

v2.0.4

<a name="2.0.4"></a>

2.0.4 (2017-09-05)

Bug Fixes

  • do not store computed properties (9d684ee)

Readme

Source

COMPUTED

Greenkeeper badge

CircleCI Coverage Status Dependencies semantic-release

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.

  • The mixin uses the loaded observer.
  • It only runs when a single instance gets loaded, e.g. it checks ctx.instance.
  • It only runs when it is a new instance, e.g. it checks ctx.isNewInstance.
  • It overrides the configured property if one exists in the data source.

INSTALL

npm install --save loopback-ds-computed-mixin

SERVER CONFIG

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" ] } }

CONFIG

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'; };

TESTING

Run the tests in test.js

npm test

Run with debugging output on:

DEBUG='loopback:mixin:computed' npm test

Keywords

FAQs

What is loopback-ds-computed-mixin?

A mixin for the LoopBack framework that adds computed properties to a model.

Is loopback-ds-computed-mixin popular?

The npm package loopback-ds-computed-mixin receives a total of 223 weekly downloads. As such, loopback-ds-computed-mixin popularity was classified as not popular.

Is loopback-ds-computed-mixin well maintained?

We found that loopback-ds-computed-mixin demonstrated a not healthy version release cadence and project activity. It has 3 open source maintainers collaborating on the project.

Last updated on 05 Sep 2017
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc