JSFiddle - React, Tailwind, and code Playground

by s1owjke

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/object-model.js"></script>
<b>Sandbox</b>
Play with ObjectModel (analog of flow/typescript)

JavaScript

const Product = new ObjectModel({
	name: String,
    price: Number,
    tags: ArrayModel(String),
    empty: [String], // optional property - that allow undefined and null
    another: [String, null] // strict string on null
}).defaults({
	empty: null,
    another: null
});

const Order = new ObjectModel({
	products: Product,
	total: Number
});

let productOne = new Product({
	name: "First item",
    price: 100,
    tags: ["what"],
});

let productTwo = new Product({
	name: "Second item",
    price: 200,
    tags: ["about"]
});

productOne.empty = undefined;

console.log(JSON.stringify(productOne));
console.log(JSON.stringify(productOne.another));