Manage Prototype Creep

Just to be clear, @gnoli’s current $OnAdd probably looks something like

$Prototype=$Name(parent)

Meaning that, like @wajakob, he is using the prototype mechanism to copy all the relevant metadata. (But unlike @wajakob, he removes the prototype designation after he is done using the prototype, so the list of prototypes doesn’t grow unmanageable.) If he no longer uses prototype assignment to do this, his $OnAdd will have to look like

$SourceTitle=$Name(parent)
$SourceAuthor=$Author(parent)
$SourceYear=$Year(parent)
...

as in @mdavidson’s solution. In fact, if @gnoli makes this adjustment, he will basically be using @mdavidson’s solution. Seems like a good fit here.

2 Likes

I wouldn’t use a prototype as a container for other notes (say, prototype MyReference – based on modifications of the built-in Reference prototype). Instead, I would create a new note (MyContainer) to use as a container, and assign MyReference as MyContainer’s prototype.

Why? Because the children of prototypes also become the children of notes that are assigned that prototype. (Easy to test and see this for yourself.) In your case, you are “de-prototyping” the container so the risk of mistakenly creating notes you didn’t intend to create is low.

But unless you intend for a prototype’s child hierarchy to be inheritable, it’s not a best practice to use prototypes as containers, in my opinion.

3 Likes

Ah I didn’t know that – many thanks!

very elegant solution.

See Prototypes, specifically the parts about prototypes ‘bequeathing’ children.