-
Notifications
You must be signed in to change notification settings - Fork 116
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
OJET support for ESM modules #93
Comments
ECMAScript Modules (ESM) are clearly superior to "requirejs" AMD modules and now supported by all web browsers. I'm curious why this JET project hasn't migrated to ESM?
But I think most importantly:
Attempting to illustrate the more intuitive and concise code with ESM, I created a slightly contrived example, creating a module mathUtils that supports add(), multiply() and trig functions which are imported from another module, but exported as part of mathUtils. **Example of ESM export and import ** Note: there is no extra code that must be loaded for module support as ESM modules are native to the ECMAScript standard supported by browsers since ~2017-2018 // trig.mjs (ESM)
export const sin = x => Math.sin(x);
export const cos = x => Math.cos(x);
export const tan = x => Math.tan(x); // calc.mjs (ESM)
export { sin, cos, tan } from './trig.mjs';
export const add = (a, b) => a + b;
export const multiply = (a, b) => a * b; <!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<!-- No additional JavaScript necessary for module support,
it is natively supported by ECMAScript in browsers -->
<body>
<script>
import * from './calc.mjs';
console.log('Result:', add(sin(0), cos(0)));
</script>
</body>
</html> Example of AMD (RequireJS) export and import : Note: excluding comments 73% more lines of code (excluding comments) than the ESM implementation, and less intuitive than the ESM import / export statements // trig.js (AMD)
// assumes that the client has already have loaded the Require.js module before this module
define(() => ({
sin: x => Math.sin(x),
cos: x => Math.cos(x),
tan: x => Math.tan(x)
})); // calc.js (AMD)
// assumes that the client has already have loaded the Require.js module before this module
define(['trig'], trig => ({
add: (a, b) => a + b,
multiply: (a, b) => a * b,
sin: trig.sin,
cos: trig.cos,
tan: trig.tan
})); <!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Include RequireJS to support AMD modules -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
</head>
<body>
<!-- Your application content here -->
<script>
// Load your main module
require(['calc'], function (calc) {
console.log('Result:', math.add(math.sin(0), math.cos(0)));
});
</script>
</body>
</html> Can anyone explain why JET has not migrated to ESM? |
Are there any plans to move forward from AMD modules to ESM modules with OJET?
AMD modules are considered antiquated by many with ESM modules becoming the default standard for almost all browsers.
The text was updated successfully, but these errors were encountered: