Skema: rawParent and parent

by kaelzhang

HTML

<script src="https://unpkg.com/skema/umd/jsfiddle.js"></script>
<script src="https://unpkg.com/skema/umd/skema.min.js"></script>

JavaScript

const {shape, any} = Skema

const A = shape({
	foo: {
  	when () {
    	// baz has not been processed, so it is undefined
    	log('foo.when.this.parent.baz', this.parent.baz)
    	return this.parent.baz === true 
    }
  },
  
  bar: {
  	when () {
    	// baz has not been processed, 
      // but we can get `this.rawParent.baz` here
      log('bar.when.this.rawParent.baz', this.parent.baz)
    	return this.rawParent.baz === true
    }
  },
  
  baz: any()
}, true)

const a = A.from({
	foo: 1,
  bar: 2,
  baz: true
})

success('a.foo', a.foo)
success('a', a)