Skip to content

Instantly share code, notes, and snippets.

@slaveofcode
Created July 26, 2018 07:46
Show Gist options
  • Save slaveofcode/a00f6cc53b2d4204575ec45984ea45a3 to your computer and use it in GitHub Desktop.
Save slaveofcode/a00f6cc53b2d4204575ec45984ea45a3 to your computer and use it in GitHub Desktop.
Podeng extend object
const { blueprint, types, validator } = require('podeng');
const Car = blueprint.object({
wheels: types.integer({ default: 4 }),
color: types.options(['Red', 'Green', 'Blue']),
brand: types.string
})
const Truck = blueprint.extend(Car, {
wheels: types.integer({ default: 6 })
})
Truck({brand: 'Volvo'}) // this is ok, since we're not doing validation
const truckValidator = validator(Truck);
truckValidator.validate({brand: 123, color: 'Green'}) // throw error because have empty value for wheels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment