Nestable hashtable plugin & object sealing?

For developers using the Construct 2 Javascript SDK

Post » Sat Mar 07, 2015 4:15 pm

Hey all, :)

I just started building a plugin that provides a hashtable for witch each key can be a number/string value, or it can reference a deeper hash table. Because each hashtable can have keys that link to other hashtables, you can have an arbitrarily deep tree of hashtables and data.

My concern is that I just remembered something about object sealing in the runtime.
Will sealing prevent this plugin from working?

In my plugin's runtime, in the instance class's onCreate() function, I'm only creating one property to hold the root hash table, named "rootHash".
All other modifications to the data structure from then on are done to rootHash, via C2 events/actions. That includes the addition of keys, and the creation of deeper hash tables.

I'm trying to understand if that kind of modification is possible, or if sealing the object restricts what you can add to it, or restricts what you can add to sub-objects.
I'm hoping that as long as I don't add more properties directly to the instance class (which I'm not) I should be okay.
B
26
S
17
G
8
Posts: 322
Reputation: 6,017

Post » Sat Mar 07, 2015 8:51 pm

In my experience object sealing hasn't affected my code at all. Not sure if it's because it's not being done or something, but I'd say just go forward with your plugin and if you get to the point of it not working because of sealing then look for workarounds.
B
85
S
27
G
85
Posts: 5,073
Reputation: 57,880

Post » Sun Mar 08, 2015 12:33 pm

Object sealing is shallow, so if you have a root property, you can dynamically add and delete properties from that property.

Adding/removing properties dynamically can reduce performance in modern JS engines, so the engine tries to enforce static object properties by sealing objects. I think we eventually turned that off though due to sealing ironically having a performance impact on some other JS engines :P Still best practice is to keep a static set of object properties. For a dynamic data structure though there's no problem with adding/removing properties, since that's what it's for.
Scirra Founder
B
378
S
220
G
84
Posts: 23,871
Reputation: 188,197

Post » Wed Mar 18, 2015 1:27 am

Thanks @R0J0hound and @Ashley for the suggestions and info. :)

Sounds good.
I have gone ahead with building this plugin, and it seems to be working correctly so far.
As it happens, the root object's properties are never removed or added to, as all the dynamic stuff happens inside a permanent property named "rootHash".
So it sounds like that should work. :)

I'm ultimately hoping to make a behavior version of it as well, so I can have per-instance dynamic data structures.

Also, sorry R0J0hound, for some reason I thought I posted a "thanks" reply a day or so after your response. In any case I did take your advice, so thanks. :)
B
26
S
17
G
8
Posts: 322
Reputation: 6,017


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest