-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support a Mechanism for Specifying Index/Position of Template Insertion #541
Comments
After some internal discussion. The following is the proposed design: Support For a More Declarative Template APIThe purpose of this change is to allow for content authors to have more explicit control over how template are expanded at runtime in Core Player. As Player uses JSON as a transport format, key order is not guaranteed to be preserved during serialization and de-serialization. This can result in problems with Template expansion at runtime as currently, the position of the template key relative to the attribute its being expanded into determines if the templated elements will be appended or prepended to any existing value. This may cause different behaviors of Player depending on the platform or any integration logic around Player. In order to alleviate this, a more explicit API is required to indicate where the template should be expanded at runtime. Proposed ApproachThe core idea of this solution is to maximize authoring and implementation simplicity. More robust solutions were considered but ultimately not perused due to too much complexity in one factor. For example, instead of the approach described below, an API around index based expansion would lead to problems around having to have forward knowledge of how many instanced would be expanded at runtime and thus requiring the content author maintain a complex mental model of data. Changes to the Template APITemplate elements would have a new property (to be decided during implementation) that would take information on whether the expanded data from the template should be appended (added to the end of the any existing elements) or prepended (added before any existing elements) in the location its being expanded to. Because the order of elements in an array is persevered and easy to ascertain at a glance, it is possible for content authors to accurately predict the order of multiple templates being expanded into the same slot with the same expansion behavior (e.g if there are two templates both set to append, the first template will be expanded followed by the second template). Changes to Template ProcessingDuring template expansion in the TemplatePlugin, the newly added field should be used to determine how the expanded template nodes should be inserted to the tree during parsing. In order to not break existing behavior, if no value is specified for how the template should be expanded the existing logic should be followed. As part of this change, we should introduce a warning message that a value was not specified to allow Player to require explicitly setting this at a later date. DSL EnhancementsAt the most basic level, the Template DSL component should be able to take this new property as a property and serialize it accordingly. |
Closing as the design is done. Will open up issues for implementation |
Related to #540, for cases where a template is being expanded into a property with existing assets. It would be a good feature to specify where the insertion actually happened. In the most simple case, we could support a prepend/append, property on the
template
object. However, if there are multiple existing assets we wouldn't be able to insert the expanded template in between the two elements so we may need to support expansion based on index? This also opens the door for conflicts in insertion from multiple templates because the order in which the templates are expanded is also not controllable via content so that is another parameter that might need to get added.TODO:
The text was updated successfully, but these errors were encountered: