ca2longoria / handlar.js

Simple MVC without the V or the C.
MIT License
1 stars 0 forks source link

Replace vs. Modify #1

Open ca2longoria opened 10 years ago

ca2longoria commented 10 years ago

Goal:

// replace
a.b = {c:1,d:2}
// modify
a.b.$modify({c:1,d:2})
special assignment cases
// replace
a.b = new M.Handle({c:1,d:2})
// modify
a.b = {c:1,d:2}

...or perhaps...

// replace
a.b = {c:1,d:2}
// modify
a.b = new M.Handle({c:1,d:2})
unique to original root Handle, or not
a.b = new M.Handle({c:1,d:2})
ca2longoria commented 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}))
ca2longoria commented 10 years ago

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.

ca2longoria commented 10 years ago

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?

ca2longoria commented 10 years ago

I vouch for ob assignment to an otherwise unchanged Handle, except in cases of receiving a new Handle(...).

ca2longoria commented 10 years ago

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?

ca2longoria commented 10 years ago

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...

ca2longoria commented 10 years ago

Oops, why did I do that?

ca2longoria commented 10 years ago

So far, we've refactored for modify all, but only that. Remaining are...

ca2longoria commented 10 years ago

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)

ca2longoria commented 10 years ago

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.

ca2longoria commented 10 years ago

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.

ca2longoria commented 10 years ago

AAAAAAARGH!

The handle/ob duality is causing problems. I must rid the world of this.

Issue: Remove handle/ob duality