[Helma-user] Keeping track of changes of HopObject in onPersist()

Julian Tree julian.tree at gmail.com
Tue Jun 24 09:42:28 CEST 2008


Thanks Joshua, for the info. I will play with onInit abit more to see  
how it behaves.


On Jun 16, 2008, at 7:06 PM, Joshua Paine wrote:

> On Mon, 2008-06-16 at 16:18 -0400, Julian Tree wrote:
>> Is there a way to find out if a key/field has being changed in the
>> HopObject?
>
> Not in Helma 1.x. I heard there were more events planned for Helma NG,
> so maybe there's an onChange event planned for HopObject properties,  
> but
> I don't know.
>
>> if(this.firstName.getOldValue() == this.firstName){
>
> This syntax would require deep magic, since method getOldValue would
> normally be obliterated as soon as you assigned something to  
> firstName.
>
> If HopObject.onInit works as specified, you could add these methods to
> HopObject:
>
> function onInit(){
>  var oldVals = {};
>  for(let name in this) {
>    if(!(this[name] instanceof HopObject ||
>         this[name] instanceof Function)) {
>      oldVals[name] = this[name];
>    }
>  }
>  this.cache.oldVals = oldVals;
> }
>
> function oldValue(name){
>  if(!this.cache.oldVals) return;
>  return this.cache.oldVals[name];
> }
>
> Then in your onPersist function you can write:
>
> if(this.firstName != this.oldValue('firstname')) doSomething();
>
> My sample code will only work for simple properties (not
> HopObjects/collections). And only if onInit works as advertised. I had
> some trouble with it the only time I tried to use it, but that was my
> first app and using the object db. I haven't revisited it since.
>
> -- 
> Joshua Paine <joshua at papercrown.org>
>
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user

Julian



More information about the Helma-user mailing list