Open ca2longoria opened 10 years ago
Try this:
// erase and replace
a.b = new M.Handle({c:1,d:2})
// modify *all*, walking through a.b's structure
a.b = {c:1,d:2}
// modify only what is present in the argument
a.b.$modify({c:1,d:2})
// same
a.b.$modify(new M.Handle({c:1,d:2}))
What about local functions regarding recursive deletion of listeners (and other data not stored within Handle instances)?
These three require a decision as to whether or not to clear the external data of Handles being modified, removed, or replaced.
What Handles would receive a delete event should fire that event, and obviously have their external data cleared.
So, there are three possibilities in this, regarding external data:
This digs into the philosophy of the unified object model.
Should Handles further down the tree be able to exist without their link to the root Handle?
Added goal unique to original root Handle, or not to Issue checklist.
Regarding external data ownership, what of references to a Handle that is replaced? Would those not need to be replaced by the new Handle?
This begs another question:
Should Handle get assignment really replace the calling Handle, or should its value (ob
in current source) be changed, instead?
And what are the implications of changing ob
?
I vouch for ob
assignment to an otherwise unchanged Handle, except in cases of receiving a new Handle(...)
.
So, property reassignment? Hmm... Could the internal function makeHandle be used for that, since it modifies an existing object? What happens, though, with multiple property defines over the same property?
There's also the matter of what exactly happens when a child-broken-from-root Handle is deleted, and then referenced again from elsewhere.
Possibilities include...
Oops, why did I do that?
So far, we've refactored for modify all, but only that. Remaining are...
Thought of something else. Replace obviously must have difference behavior, but modify, including via the = operator, can all call through the $modify function.
a.$modify(b)
R: traverse only where a[k] and b[k] W: traverse where a[k] or b[k], and add to a where b[k] D: as W, but remove from a where !b[k]
Say... a.$modify(b,W)
Hey, wait a minute. Doesn't the present = operator already behave recursively? I was thinking of using a walkPair(a,b,k,f) function. That would allow for easy selection between the three behaviors in $modify.
No, you wait! Observe, here...
// Deleting... <- hnoto
hnoto.map(function(p){...});
// Changing... <- hando
hando.map(function(p){...});
// Adding... <- onoth
onoth.map(function(p){...});
During 32b9704's refactoring, the above was implemented. What if some kind of conditional could be passed down to speficfy which of these actions to take?
Delete, change, add -> Change, add, delete -> R, RW, RWD
Let's try it.
AAAAAAARGH!
The handle/ob duality is causing problems. I must rid the world of this.
Issue: Remove handle/ob duality
Goal:
unique functions, or special assignment cases
unique functions
special assignment cases
...or perhaps...
unique to original root Handle, or not
a.b
's child Handles would be deleted, their external data cleared.