JSFiddle - React, Tailwind, and code Playground

by andrewpetersen15

HTML

<script src='https://cdn.rawgit.com/DroopyTersen/droopy-binding/master/dist/droopy-binding.polyfill.js'></script>
	<div id='container' data-id='{{id}}' style='visibility: {{visibility}}'>
		Some text here for id: {{id}}
		<h1>{{title}}</h1>
		<p>{{details}}</p>
		<strong>Author: {{author.firstName}} {{author.lastName}}</strong>
		<br/>
		<strong>Selected: {{selectedItem}}</strong>
        
        <p>Here is an array of complex objects</p>
        <ul data-each='complexItems'>
			<li>{[name]}</li>
		</ul>
        
        <hr/>
        <h4>Check out the 2 way binding</h4>
		<div style='margin-top:40px'>
			<label>Title:</label>
			<input id='titleTextBox' value='{{title}}' />
		</div>

		<div style='margin-top:40px'>
			<label>Author Last Name:</label>
			<input id='authorTextBox' value='{{author.lastName}}' />
		</div>
		<br/>

        <label>Select an item:</label>
		<select value='{{selectedItem}}' data-each='stringItems'>
			<option value='{[_]}'>{[_]}</option>
		</select>
		<br/>
	</div>

JavaScript

// setup the initial object to bind to
		var model = {
		    id: 123,
		    title: "Initial Title",
		    details: "These are the details",
		    visibility: "visible",
		    author: {
		        firstName: "Andrew",
                lastName: "Petersen",
		        id: "12"
		    },
		    stringItems: [
		    	"one",
		    	"two",
		    	"three",
		    	"four"
		    ],
		    complexItems: [
		    	{
		    		name: "itemOne",
		    		id: 1
		    	}, {
		    		name: "itemTwo",
		    		id:2
		    	}
		    ],
            selectedItem: "-1",
		};

		// create the binding and call 'init()' to display the default values
		var binding = new DroopyBinding('container', model);

		// Pretend we made an async ajax request and got new property values for our model
		// The 'title' and 'details' will automatically update in the view
		// No UI code required
		setTimeout(function(){
		    model.title = "My Title",
		    model.details = "This simulates data changing after an async ajax request";
            model.complexItems[0].name = "I'm an array item nested property!";
            model.complexItems.push({name: "And I'm a whole new item"});
		}, 2000);