DOM API: How to access public Mutable Data?

I’m confused about how to get a handle for an existing Mutable Data. I see window.safeMutableData.newPublic is for creating a new one, and I think I was told this was also for accessing an existing one. But you still need to be able to check if it exists before accessing it with newPublic, otherwise you’d create one and you don’t necessarily want to create it at this point.

So how is one to a) test if a public MD exists, or b) access it without creating it if it doesn’t in fact exist?

Thanks.

1 Like

The newpublic function only retrieves the handle for the MD structure it doesn’t commit to the network. To check if an MD structure exists you get its version if it fails it doesn’t exist, although it would be nice to have an explicit ping feature for MD, immu data and safe websites.

4 Likes

I have noticed this naming before, and I think it is not the best to describe what it does.
GetPublic would be closer to the description of

It can seem like trivial stuff, but I have always been convinced (and I think it is also generally considered so) that naming is a very important part of coding.

I actually have quite a few of those in mind here and there. But some depends on the level (system or higher level) and then there are different ideas and schools of course.

4 Likes

I’m with you on the value of getting names right, and this is the time to make those changes if there’s good reason.

It is also a problem with the description though - reading the explanation of that function doesn’t give a hint of what @Joseph_Meagher says here (thanks Joseph BTW) so it is quite hard here and in a few places I think, for people to understand what individual functions do.

The example code fragments are invaluable here and in most cases have been adequate for me, but not all. In this case, adding further code fragments for each case (such as test if it exists, as well as create new etc would do the job too).

4 Likes