Skip to content

refactor(JS): Encapsulated JS in a module instead of using the gobal scope#82

Open
JBBianchi wants to merge 4 commits intoserdarciplak:masterfrom
neuroglia-io:refactor-js-module
Open

refactor(JS): Encapsulated JS in a module instead of using the gobal scope#82
JBBianchi wants to merge 4 commits intoserdarciplak:masterfrom
neuroglia-io:refactor-js-module

Conversation

@JBBianchi
Copy link
Copy Markdown

@JBBianchi JBBianchi commented Mar 14, 2023

This refactor encapsulate the JS code in its own module instead of using the global scope which could be tampered with.

Important notice, support for dotnet standard 2.0 has been dropped because of the use of IJSObjectReference.

The JS has been cleaned a bit:

  • Removed the use of nested objects and (possibly) misleading this
  • Used arrow functions everywhere instead of some kind of mix
  • Removed deprecated var, enforced proper use of const/let (it was used randomly)
  • Added missing null checking (of editor for instance)
  • Used (de)structuring/spread operator
- /*...*/.editors.push({ id: id, editor: editor, dotnetRef: dotnetRef });
+ editors.push({ id, editor, dotnetRef });

- editorHolder.editor.addAction({
-     id: actionDescriptor.id,
-     label: actionDescriptor.label,
-     keybindings: actionDescriptor.keybindings,
-     precondition: actionDescriptor.precondition,
-     keybindingContext: actionDescriptor.keybindingContext,
-     contextMenuGroupId: actionDescriptor.contextMenuGroupId,
-     contextMenuOrder: actionDescriptor.contextMenuOrder,
-     run: function (editor, args) {
-         editorHolder.dotnetRef.invokeMethodAsync("ActionCallback", actionDescriptor.id);
-     }
- })
+ editorHolder.editor.addAction({
+     ...actionDescriptor,
+     run: (editor, args) => editorHolder.dotnetRef.invokeMethodAsync("ActionCallback", actionDescriptor.id)
+ });
  • Replaced null checking with shorthands:
- if (model == null)
+ if (!model)

- if (options == null)
-     options = {};
+ options = options || {};

- return editorHolder == null ? null : editorHolder.editor;
+ return editorHolder?.editor;
  • Enforced strict comparisons (===/!== instead of ==/!=).
  • Avoided unnecessary rewraps
- defineTheme: function (themeName, themeData) {
-     monaco.editor.defineTheme(themeName, themeData);
-  }
+ export const defineTheme = monaco.editor.defineTheme;

@serdarciplak
Copy link
Copy Markdown
Owner

Thanks for this PR. As this is a breaking change, I'll merge these changes in v4.0.0

@StephenOTT
Copy link
Copy Markdown

+1

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.

3 participants