Skip to content

fashion-js/fashion-model-defaults

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fashion-model-defaults

fashion-model mixin that attaches an applyDefaults method to the model prototype.

Using default as a standard value:

var DefaultsMixin = require('fashion-model-defaults');

var Person = Model.extend({
  mixins: [DefaultsMixin],
  properties: {
    name: {
      type: String,
      default: 'Bob'
    },
    age: Number
  }
});

var bob = new Person({
  age: 30
});

bob.applyDefaults();
bob.getName(); // Returns 'Bob'

Using default as a function:

var DefaultsMixin = require('fashion-model-defaults');

var Person = Model.extend({
  mixins: [DefaultsMixin],
  properties: {
    name: {
      type: String,
      default: function() {
        return 'Bob';
      }
    },
    age: Number
  }
});

var bob = new Person({
  age: 30
});

bob.applyDefaults();
bob.getName(); // Returns 'Bob'

About

fashion-model mixin that allows defaults on properties

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published