Better know a framework #26: Dynamic ViewFactory

Awhile ago, I created this topic Better know a framework #18: what processContent is and what it is used for to help folks understand more about processContent and its common usages.

There’s another usage that processContent enables: dynamic view factory per usage. This is achieved via setting the viewFactory property on a custom element instruction to override the default view factory associated with it (the custom element).

A contrive example of this would be a <field/> custom element, that will determine where should the <slot> element is, based on its content. Normally dynamic slot position cannot be achieve in shadowDOM emulation. But with processContent and dynamic view factory, we can easily support it.

Example here https://gist.dumber.app/?gist=6ecafbe67a10f6a22dc2e36e859c2418&open=src%2Ffield.js

P.S: thanks @MaximBalaganskiy for asking about this

7 Likes