BetaBetaGet a factory function for the given view type
With a single factory registered, that factory is returned as it is. With
several, the returned factory calls each one in turn and passes the view
from one to the next. If nothing is registered for the type, returns
undefined.
the type of view to get a factory for (e.g., 'list', 'card', 'table')
a composite factory function, or undefined if no factories are registered
import { LimeObject, PlatformServiceName } from '@limetech/lime-web-components';
const registry = platform.get(PlatformServiceName.ViewFactoryRegistry);
// The 'list' key fixes the return type, so `factory` is already known to
// build a ListItem from a LimeObject.
const factory = registry.getFactory('list');
const scope = platform.get(PlatformServiceName.ContextRegistry).scope({
host: document.createElement('my-list'),
});
// `getFactory` returns undefined when nothing is registered for the type,
// so the call has to be guarded.
const toListItem = (limeobject: LimeObject) => factory?.(limeobject, scope);
BetaRegister a factory for a given view type
Adds a factory to the chain for the view type. A factory registered later runs after the ones already registered.
A factory has to handle a view of undefined, which is what the first
factory in a chain receives.
A factory must not change the view it receives. See
ViewFactory for what it may do with it instead.
the type of view to register a factory for (e.g., 'list', 'card', 'table')
factory function to create or transform a view of the specific type
Registry for view factories
A view factory is used to create or transform a view representation from data, typically a LimeObject but can also be any other data type. View factories enable components to customize how data is displayed without modifying the core rendering logic.
Multiple factories can be registered for the same view type. They run in the order they were registered, and each one receives the view returned by the previous factory. The first receives
undefined, because nothing has built a view yet.A factory does not own the view it receives. It returns a new object instead of changing the one it was given. See ViewFactory for the full rule.
registerFactory and getFactory take their types from the view type name, so neither call names a type argument. A name and its factory type become known through a module augmentation, written by the package that introduces the view type.
A package that introduces a view type of its own writes the whole augmentation itself, next to the component that renders the view. TypeScript merges every such block, so the platform's view types and your own are both known at the call site. Code that registers a factory for a view type that already exists writes none of this.
A name that no augmentation declares still compiles, because these blocks add to the declarations below rather than replacing them. Its factory falls back to
unknownfor both data and view, which is the signal that the augmentation is missing.Example: Chaining multiple factories
Example: One time setup, introducing a view type of your own