Force update of a tangle?

139 views
Skip to first unread message

usernam...@gmail.com

unread,
Mar 11, 2015, 4:54:57 PM3/11/15
to tangl...@googlegroups.com
Hello all!

I only just discovered Tangle today, and I'm very excited about it. I've been messing around with it and am wondering whether anyone has tricks for taking a little extra control over when a tangle updates. For example, I've thrown together a silly little page that just uses a toggle and a number field to add to or subtract from a number. I'm also trying to make it display starting text that changes after the first update:  

<script language="javascript">
var tangletest = new Tangle (document.getElementById("tangletest"), {
 initialize
: function () {
   
this.foo = 100;
   
this.bar = 0;
   
this.optoggle=true;
   
this.wordtoggle = -2;
 
},
 update
: function () {
   
this.wordtoggle += 1;
   
if ( this.optoggle ) {  
     
this.foo += this.bar;
   
} else {
     
this.foo -= this.bar;
   
}
 
}
});
</script>

...

<div id="tangletest">
 The
<span class="TKSwitchPositiveNegative" data-var="wordtoggle">
   
<span>updated</span>
   
<span>starting</span>
 
</span> value is: <span data-var="foo"></span>
 
<br />
 
<span class="TKToggle TKSwitch" data-var="optoggle">
 
<span>SUBTRACT</span><span>ADD</span>
 
</span>
 
<span class=TKNumberField data-var="bar"></span>
</div>


There are a couple of issues here. 

The main thing is that in this particular use case it's a problem to have the foo update whenever bar (or the +/- toggler!) changes. Since it updates with every keystroke, I don't even get the desire results since typing "10" ends up actually adding 11. What I could see myself wanting instead something where I set the toggler, put a value into the bar field, and then click a `Go!` button to perform the update. Less snazzy and web 3.0 (or whatever we're on nowadays), but it has its uses. 

I'd been thinking I could kludge something together by using a regular <input> field that could be checked by the update code, and then add a button that forces the update with an onclick event. However, the tangletest js var doesn't appear to have a .update() method as I'd hoped it would, so this is proving trickier expected.

Relatedly, the trick I'm using for the 'wordtoggle' field feels really kludgey. What I think I really want here is a method that fires either only on the first update, or only on subsequent updates.

Any suggestions for dealing with either of these? 

Thanks a bunch to everone who has worked on Tangle! I hope I don't come across as negative here or anything. In fact I'm really excited about figuring out some interesting ways to use it, and my initial explorations just happen to have taken me into a weird place and now I'm curious about this. XP

--Brad
Reply all
Reply to author
Forward
0 new messages