node-codein icon indicating copy to clipboard operation
node-codein copied to clipboard

dynamic object properties

Open albertz opened this issue 11 years ago • 3 comments
trafficstars

I have the case that I have some complex objects which have dynamic properties (defined via get functions) in their prototypes.

Currently, because of the Object.prototype.hasOwnProperty check in stringify, attributes from parent prototypes wont be shown at all. That is simple to change and already almost always what you probably want (I guess).

However, for my use case, that change is of course not enough. I added some more code which checks if a property is defined via a get-function, via Object.getOwnPropertyDescriptor. The client shows this as a placeholder and if the user requests to show the property, the clients send such request to the server. To make that possible, you need to keep some reference to the object on the server in case for a later request. I have introduced a small and simple object cache, where I assign a new id to a new object. This id is sent to the client and the client uses this id in its requests. I also extended the jsencr function a bit to cover this.

albertz avatar Mar 27 '14 14:03 albertz

Hello there.

Thanks for giving time to this. I'm going to try a local test, not sure what steps to follow.

Silviu-Marian avatar Jun 10 '14 13:06 Silviu-Marian

Ok so, I have the changes locally and need to test them. Can you please provide a simple test pattern? How should this feature work?

There's a couple of bits I don't like and maybe we can make some changes.

Silviu-Marian avatar Jun 10 '14 14:06 Silviu-Marian

You need dynamic attributes, like this:

obj = {};
Object.defineProperty(obj, 'dyn_attrib', {get: function() {
     return obj; // or whatever ...
} , enumerable:true});

albertz avatar Jun 10 '14 14:06 albertz