[General] Storing Values when a Morph is Persisted, How To
Robert Krahn
robert.krahn at student.hpi.uni-potsdam.de
Wed Mar 4 08:46:50 CET 2009
Hi Phil,
the getTrait and setTrait methods are used by shapes, not morphs. All
instance variables of morphs are persistent a priori. I modified your
test code a bit:
Morph.subclass("MyPersistedMorph", {
handlesMouseDown : Functions.True,
initialize : function($super) {
console.log('PersistedMorph.initialize');
$super(new lively.scene.Rectangle(new Rectangle(100, 100, 200, 200)));
this.setFill(Color.green);
console.log('PersistedMorph.initialize weight: ' + this.weight); //
will always be undefined because
// initialize isn't called for deserialization
},
onDeserialize: function() {
console.log('PersistedMorph.onDeserialize weight: ' +
this.weight); // This works
},
onMouseDown : function($super, event) {
console.log('PersistedMorph.onMouseDown');
console.log('PersistedMorph.onMouseDown weight: ' + this.weight);
this.weight = 100;
return true;
}
});
Robert
On Mar 3, 2009, at 11:18 PM, Philip Weaver wrote:
> I struggled with a very simple yet important subject and I just want
> to post a possible solution here. I wanted to persist some simple
> values when one of my morph instances was persisted. I am not using
> the Widgets class at this time. My goal is persist some layout
> constraints on a morph.
>
> The Morph class does extend from lively.data.Wrapper.
> lively.data.Wrapper provides methods for setTrait and getTrait which
> do store and restore automatically when a Morph is serialized and
> deserialized.
>
> Another approach may be to use models. Because I'm not really yet
> using the Widgets class I don't really have models working yet.
> There appears to be no documentation yet for using models except for
> Examples.js.
> _______________________________________________
> General mailing list
> General at livelykernel.sunlabs.com
> http://livelykernel.sunlabs.com/mailman/listinfo/general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://livelykernel.sunlabs.com/pipermail/general/attachments/20090303/07c53389/attachment.html
More information about the lively-kernel
mailing list