added demo

simplified bind
This commit is contained in:
Aki Rodic 2014-08-26 18:01:16 -07:00
parent 8dcce60d1d
commit 8ffecf6987
3 changed files with 65 additions and 14 deletions

49
demo.html Normal file
View File

@ -0,0 +1,49 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>dat-gui</title>
<link rel="import" href="gui.html">
</style>
</head>
<body>
<script src="../underscore/underscore.js"></script>
<script>
Gui.ready( init );
var object;
function init() {
var gui = new Gui();
object = {
numberProperty: 0,
stringProperty: 'hey',
booleanProperty: false,
functionProperty: function() {
}
}
gui.add( object, 'numberProperty', 0, 1 ); // Slider
gui.add( object, 'stringProperty' ); // Text box
gui.add( object, 'booleanProperty' ); // Check box
gui.add( object, 'functionProperty' ); // Button
console.log( gui );
}
</script>
</body>
</html>

View File

@ -2,4 +2,4 @@
<script src="controller-base.js"></script> <script src="controller-base.js"></script>
<polymer-element name="controller-base" attributes="object path"></polymer-element> <polymer-element name="controller-base" attributes="object path value"></polymer-element>

View File

@ -26,31 +26,33 @@ Polymer('controller-base', {
this.object = object; this.object = object;
this.path = path; this.path = path;
if ( this._observer ) { // if ( this._observer ) {
this._observer.close(); // this._observer.close();
delete this._observer; // delete this._observer;
} // }
var _this = this; this.bind('value', new PathObserver(this.object, this.path));
this._observer = new PathObserver( this.object, this.path ); // var _this = this;
this._observer.open( function( newValue ) {
_this.value = newValue; // this._observer = new PathObserver( this.object, this.path );
// this._observer.open( function( newValue ) {
} ); // _this.value = newValue;
this.value = this.object[ this.path ]; // } );
// this.value = this.object[ this.path ];
}, },
valueChanged: function() { valueChanged: function() {
if ( this._observer ) { // if ( this._observer ) {
Path.get( this.path ).setValueFrom( this.object, this.value ); // Path.get( this.path ).setValueFrom( this.object, this.value );
} // }
this.update(); this.update();