Having been pointed in their direction by Marcel, I've been playing around
with harmony proxies as an alternative means of abstracting Mumps
GlobalNodes from the standard JS object approach I originally used.
Proxies are certainly interesting and I can see how they allow me to
abstract a single level of subscripting, ie:
^myGlobal("name") = "Rob"
I'm able to get the value using myGlobal.name
Here's the code I use for this:
---------
var globalNode = function(node) {
return Proxy.create({
get: function(proxy, property) {
var subs = node.subscripts.slice(0);
subs.push(property);
var gnode = {global: node.global, subscripts: subs};
return db.get(gnode).data;
}
});
};
var myGlobal = globalNode({global:'myGlobal', subscripts: []});
console.log(myGlobal.name);
---------
This code allows me to get any 1st-level subscript from ^myGlobal.
However, I'm struggling to figure out if/how I could go deeper, eg:
^myGlobal("address","town") = "London"
I'd like to retrieve using the syntax: myGlobal.address.town
The way I currently manage to do this (ie in my original non-proxy
approach) is to use the $() method which returns myGlobal.address as an
instance of a GlobalNode object, which then provides me with the necessary
methods for this lower level of subscripting.
But with the proxy approach, myGlobal.address will return the value of
^myGlobal("address"), not a pointer to the GlobalNode itself. I can't see
how to get past or around this ambiguity.
I have no doubt I'm just missing something, but I can't see how to be able
to chain GlobalNode subscripts and get to the corresponding Global Node's
value. Anyone got any ideas/pointers?
Rob
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.