ljmotta commented on code in PR #2105:
URL:
https://github.com/apache/incubator-kie-tools/pull/2105#discussion_r1439986375
##########
packages/online-editor/src/editor/EditorPage.tsx:
##########
@@ -331,34 +331,48 @@ export function EditorPage(props: Props) {
setContentErrorAlert.show();
}, [setContentErrorAlert]);
- const dmnLanguageService = useMemo(() => {
- if (!workspaceFilePromise.data?.workspaceFile) {
- return;
- }
+ const [dmnLanguageService, setDmnLanguageService] =
useState<DmnLanguageService | undefined>();
+ useCancelableEffect(
+ useCallback(
+ ({ canceled }) => {
+ if (!workspaceFilePromise.data?.workspaceFile) {
+ return;
+ }
- if (workspaceFilePromise.data?.workspaceFile.extension.toLocaleLowerCase()
!== "dmn") {
- return;
- }
+ if
(workspaceFilePromise.data?.workspaceFile.extension.toLocaleLowerCase() !==
"dmn") {
+ return;
+ }
- return new DmnLanguageService({
- getDmnImportedModelResource: async
(importedModelPathRelativeToWorkspaceRoot: string) => {
- try {
- const fileContent = await workspaces.getFileContent({
- workspaceId: workspaceFilePromise.data?.workspaceFile.workspaceId,
- relativePath: importedModelPathRelativeToWorkspaceRoot,
- });
+
workspaceFilePromise.data?.workspaceFile.getFileContentsAsString().then((modelContent)
=> {
+ if (canceled.get()) {
+ return;
+ }
- return {
- content: decoder.decode(fileContent),
- pathRelativeToWorkspaceRoot:
importedModelPathRelativeToWorkspaceRoot,
- };
- } catch (err) {
- console.debug("ERROR: DmnLanguageService.getImportedModel: ", err);
- return undefined;
- }
+ setDmnLanguageService(
+ new DmnLanguageService({
+ getModelContent: async (args: {
normalizedPosixPathRelativeToWorkspaceRoot: string }) => {
+ try {
+ const fileContent = await workspaces.getFileContent({
+ workspaceId:
workspaceFilePromise.data?.workspaceFile.workspaceId,
+ relativePath:
args.normalizedPosixPathRelativeToWorkspaceRoot,
+ });
+
+ return {
+ content: decoder.decode(fileContent),
+ normalizedPosixPathRelativeToWorkspaceRoot:
args.normalizedPosixPathRelativeToWorkspaceRoot,
+ };
+ } catch (err) {
+ console.debug("ERROR: DmnLanguageService.getDmnModelContent:
", err);
+ return undefined;
+ }
+ },
+ })
+ );
+ });
},
- });
- }, [workspaces, workspaceFilePromise.data?.workspaceFile]);
+ [workspaces, workspaceFilePromise.data?.workspaceFile]
+ )
+ );
Review Comment:
You're right. I made a change to set the model content on the class
constructor and I've changed back to avoid one instance per file. I'll change
it back to a `useMemo`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]