[Seaside] registerObjectForBacktracking, submit and execute block

radoslav hodnicak rh at 4096.sk
Sun Aug 29 12:29:24 CEST 2004


On Sun, 29 Aug 2004, radoslav hodnicak wrote:

> Registering object for backtracking doesn't do what you probably
> think it does. It's only sensitive to changes of objects, *not* object's
> contents.
>
> holder := WAStateHolder new.
>
> holder contents: (OrderedCollection with: 1 with: 2).
>
> holder contents add: 3. "NO CHANGES HERE, STILL THE SAME OBJECT IN HOLDER"
>
> holder contents: (holder contents copyWith: 3). "NEW OBJECT IN HOLDER,
> WILL BACKTRACK"

Ok I didn't explain this good enough - backtracking works for changing
object state too - but it works on shallow copy so the changes it can
detect are only one level deep.

Take this example with OrderedCollection. The items are internally held in
an array.

anOrederedCollection (object1)
--has anArray(items ...) (object2)

when you register object1 for backtracking, it makes a shallow copy of it,
which means they share the same instance of object2. And on backtrack, it
looks whether object1 = object1 copy - and it does, because adding and
removing items changed the same array (object2). If you changed a simple
instvar holding a string or whatever, then it would work as expected.
Clear enough?

rado
-- 
gentleman, n. - a man who knows how to blog, but doesn't



More information about the Seaside mailing list