Skip to content
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

Create widget content only on first attachment #43

Merged
merged 1 commit into from
Sep 30, 2019
Merged

Conversation

spoenemann
Copy link
Contributor

Fixes #42.

I also added an injection key DiagramWidgetFactory that can be used to create a custom DiagramWidget without the need to override createWidget in the WidgetManager (which is error-prone because you have to copy code from the superclass).

In case you have multiple diagram types with different DiagramWidget subclasses, you can use a child container to link each widget to its manager:

bind(MyDiagramManager).toDynamicValue(context => {
    const childContainer = new Container();
    childContainer.parent = context.container;
    childContainer.bind(DiagramWidgetFactory).toFactory(_ => {
        return (options: DiagramWidgetOptions, widgetId: string, diContainer: Container, connector?: TheiaSprottyConnector) =>
            new MyDiagramWidget(options, widgetId, diContainer, connector);
    });
    return childContainer.resolve(MyDiagramManager);
}).inSingletonScope();

Copy link
Contributor

@JanKoehnlein JanKoehnlein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@spoenemann spoenemann merged commit 22d2f8a into master Sep 30, 2019
@spoenemann spoenemann deleted the issue42 branch September 30, 2019 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DiagramWidget is initialized multiple times
2 participants