mekanika / skematic

Data model & rule engine for JS objects
9 stars 0 forks source link

Sub-schema objects don't intialise on createFrom #20

Closed cayuu closed 9 years ago

cayuu commented 9 years ago
var sweet = {
  cool: {
    title: {type:'string', default:'wooot!'}
  }
};

Skematic.createFrom(sweet);
// -> { cool: undefined } // :(

What you'd expect is:

{ cool: {title: 'wooot!'} }

Leads into a question about how to represent schema'ed arrays that have a non-empty default value:

var moo = {
  rad: {
    type:'array',
    schema: {
      title: {type:'string', default:'sweet'}
    },
    // See what I'm trying to do here? I want a single element in the array as a default.
    default: [ {} ]
  }
};
// Expect createFrom to output:
// { rad: [ {title: 'sweet'} ] }

Probably relates back to #18 (should createFrom become a flag on .format())