-
Notifications
You must be signed in to change notification settings - Fork 22
Description
As discussed on slack, we want to achieve having certain elements in ApiDOM with additional metadata (either during creation or during lifecycle), but not having them as higher minim types, but rather keep them as primitives
. In order to achieve that we have two strategies:
1.) Extending primitive types without overriding element property
I fancy this solution the most. We just extend the primitive
types (subclass it) and in constructors we add the needed metadata. Our predicates will detect those subclases as standard primitive
types (I'll refrence to those as subclasses). When minim tree gets serialized into string and deserialized into minim instances again, these subclasses will not be used, because minim will map it's own primitive types. To say it in another way - subclasses are exclusively mechanism used by adapter during initial tree creation.
2.) Using JavaScript constructors to act like factory functions
JavaScript allows us to switch the instance that is being created by the constructor - by returning another value. Effectively the subclass acts like a factory function for creating another element.
Concern:
There is a question if we want to have these decorated primitive elements to have additional behavior (methods, properties) in future. If there is just one case where answer will be yes
, then both of these strategies cannot deliver, and the only way to achieve additional behavior is to properly extend minim primitive types and giving them their own element name.