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

bug: maintain inject/provide context #673

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/dockview-vue/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function mountVueComponent<T extends Record<string, any>>(
let vNode = createVNode(component, Object.freeze(props));

vNode.appContext = parent.appContext;
vNode.appContext.provides = {
...(vNode.appContext.provides ? vNode.appContext.provides : {}),
...((parent as any).provides ? (parent as any).provides : {}),
};

Choose a reason for hiding this comment

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

you are trying to modify the global context ? please don't do that...


render(vNode, element);

Expand Down
23 changes: 21 additions & 2 deletions packages/docs/templates/dockview/basic/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,35 @@ import {
} from 'dockview-vue';

const Panel = defineComponent({
inject: ['vu3ProvideInjectEvidenceTestMessage'],
name: 'Panel',
props: {
params: {
type: Object as PropType<IDockviewPanelProps>,
required: true,
},
},
setup(props) {
data() {
return {
title: props.params.api.title,
title: '',
message: this.vu3ProvideInjectEvidenceTestMessage ?? 'not found',
};
},
mounted() {
const disposable = this.params.api.onDidTitleChange(() => {
this.title = this.params.api.title;
});
this.title = this.params.api.title;

return () => {
disposable.dispose();
};
},
template: `
<div style="height:100%; color:red;">
Hello World
<div>{{title}}</div>
<div>{{message}}</div>
</div>`,
});

Expand All @@ -40,6 +54,11 @@ const App = defineComponent({
});
},
},
provide() {
return {
vu3ProvideInjectEvidenceTestMessage: 'Hello from the provider',
};
},
template: `
<dockview-vue
style="width:100%; height:100%"
Expand Down