Suggestion for a change in attribute compute

Would it be possible for an attribute to compute it’s value from the supplied attributes? As it is, the compute function gets a reference to the current object and any content; could it also get the attrs? That way, I could create attributes computed from other attributes. My current approach feels a bit kludgy.

What kind of attribute are you implementing? (And how are you computing it?)

Well I’m implementing a way of embedding (youtube|vimeo) videos. So I have a Video node type, which has a command as well as an autoInput with shortcode. Since I want the user to be able to input the “regular” URL, but I need the embed URL in the DOM, I have an internal representation with just “type” (youtube|vimeo) and “id” (the respective video ID) as attributes.

As it is, I have static helper methods for parsing/serializing URL to and from id and type, and so I use something like create(Video.fromURL(url)) when creating the node. This works, but it would be cleaner if I could specify it in the object definition somehow.

Here’s a gist where I have patched the command to pass attrs so in the autoInput I pass the attrs (the way I would like) and in the command I use the other method.

Would it make sense to put the URL/id sanitizing somewhere in the UI code that inserts the node to begin with?

Perhaps. I notice I’m struggling with the object model here, I don’t really know where to put this kind of behaviour in a NodeType and what properties and methods of an instance I can access in e.g. serializeDOM.