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

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JBBianchi
Copy link

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 string comparisons (===/!== instead of ==/!=).
  • Avoided unnecessary rewraps
- defineTheme: function (themeName, themeData) {
-     monaco.editor.defineTheme(themeName, themeData);
-  }
+ export const defineTheme = monaco.editor.defineTheme;

@serdarciplak
Copy link
Owner

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

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