modella-computed

Define computed properties on modella models.

Usage no npm install needed!

<script type="module">
  import modellaComputed from 'https://cdn.skypack.dev/modella-computed';
</script>

README

modella-computed

Define computed properties on modella models.

build status

Usage

var computed = require('modella-computed')
var Mustard = model('Mustard')
  .use(computed)
  .attr('color', {
    defaultValue: 'Golden'
  })
  .attr('flavor', {
    // defines a constant
    value: 'Spicy'
  })
  .attr('name', {
    // defines a getter, invoked with model bound as `this` context
    get: function () {
      return this.flavor() + ' ' + this.color()
    }
  })

var mustard = new Mustard({ color : 'Brown' });
mustard.name(); // 'Spicy Brown'

mustard.set({ color: 'Yellow' })
mustard.name(); // 'Spicy Yellow'