Skip to content

Automatically register injectors used in dojo/framework #285

@agubler

Description

@agubler

Enhancement

To use a stores, routing, theming and i18n requires consumers to manually register each one with a registry and pass the registry when mounting the application.

Current Example:

import { tsx } from '@dojo/framework/widget-core/tsx';
import renderer from '@dojo/framework/widget-core/vdom';
import Registry from '@dojo/framework/widget-core/Registry';
import { registerThemeInjector } from '@dojo/framework/widget-core/mixins/Themed';

import theme from './MyTheme';
import App from './App';

const registry = new Registry();
const themeInjector = registerThemeInjector(theme, registry);

const r = renderer(() => <App />);
r.mount({ registry });

The boilerplate required increases for each feature that leverages injectors. It would be ideal if injectors could be automatically registered with the applications registry. If there is no registry passed to the renderer a registry it would be created internally.

To ensure that only code required is included in the end users bundle, this could require some thought on the build process on how we could elide the feature registration modules.

A consideration will be that some injectors require values to be passed during the registration, for example the routing configuration when registering the router.

A possible example:

import { tsx } from '@dojo/framework/widget-core/tsx';
import renderer from '@dojo/framework/widget-core/vdom';

import theme from './MyTheme';
import App from './App';

const r = renderer(() => <App />);
r.mount({ injectors: { theme }});

Passing theme would automatically factory a registry for the application and register the theme injector.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions