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

add init data and loadData event callback to be init #1786

Merged
merged 5 commits into from
Mar 16, 2024

Conversation

pigwing
Copy link
Contributor

@pigwing pigwing commented Mar 13, 2024

Description

因为当_drawflowProxy = await DrawflowJSModule.Init(ElementReference.GetSelector()!, _interopHandleReference, Mode);执行后,页面相关dom元素才会被渲染以及事件发生挂钩对接,若当有基础dataflow的json数据,这时候是无法初始化的,增加初始json数据参数以及loadData的event callback,协助初始化,不需要在first render的方法内进行delay.....等待相关dom渲染完成后再初始化控件的json数据..

@capdiem
Copy link
Contributor

capdiem commented Mar 13, 2024

@pigwing 在OnAfterRender里也要手动延迟吗?你提议的API有点冗余,如果一定需要,可以是一个 Func<string> 类型的参数。

[Parameter] public Func<string> DataInitializer { get; set; }

@pigwing
Copy link
Contributor Author

pigwing commented Mar 14, 2024

@pigwing 在OnAfterRender里也要手动延迟吗?你提议的API有点冗余,如果一定需要,可以是一个 Func<string> 类型的参数。

[Parameter] public Func<string> DataInitializer { get; set; }

是的,因为在webview2里面呢,

options.RootComponents.RegisterCustomElement<CustomElement>("my-custom-element");

是不支持的,需要做

options.RootComponents.RegisterForJavaScript<CustomElement>("my-custom-element");

用JavaScript进行component渲染,要依赖dom节点,但因为组件们各自的firstRender时间不一致,会导致我页面的firstRender会比drawFlow要早,所以就需要delay一下等待drawFlow渲染完毕以后,再import出现相关的dataflow的dom,这时候才能去用js渲染对应的customer element.
image
let targetElement = document.getElementById('quoteContainer');这块
https://learn.microsoft.com/zh-cn/aspnet/core/blazor/components/js-spa-frameworks?view=aspnetcore-8.0#render-razor-components-from-javascript

@pigwing
Copy link
Contributor Author

pigwing commented Mar 14, 2024

做成Func也行,只要在dataflow的firstRender时候执行一次import也能正常初始化,这时候我在OnImport的event callback里面做customer element的构建就好

@pigwing
Copy link
Contributor Author

pigwing commented Mar 14, 2024

刚试了下.这样改还是有加载顺序的问题

@pigwing
Copy link
Contributor Author

pigwing commented Mar 14, 2024

OnImport在组件初始化的时候会被执行一次,这时候依然找不到相关的dom进行customer element渲染

@pigwing
Copy link
Contributor Author

pigwing commented Mar 14, 2024

OnImport在组件初始化的时候会被执行一次,这时候依然找不到相关的dom进行customer element渲染

sorry,我错了,这样改就可以了.我测试通过了...

Copy link
Contributor

@capdiem capdiem left a comment

Choose a reason for hiding this comment

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

src/Masa.Blazor/Components/Drawflow/MDrawflow.cs Outdated Show resolved Hide resolved
src/Masa.Blazor/Components/Drawflow/MDrawflow.cs Outdated Show resolved Hide resolved
@capdiem
Copy link
Contributor

capdiem commented Mar 15, 2024

@pigwing 代码好像没有修改好?

Copy link
Contributor

@capdiem capdiem left a comment

Choose a reason for hiding this comment

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

Thanks!

@capdiem capdiem merged commit 08df700 into masastack:main Mar 16, 2024
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.

None yet

2 participants