Browse Source

[js] Add `Lib.dynamicImport()` method (#10465)

* [js] Add `Lib.dynamicImport()` method

* [js] Fixed the return type of `Lib.dynamicImport()` method
Cédric Belin 3 years ago
parent
commit
ec4a73dc81
1 changed files with 8 additions and 0 deletions
  1. 8 0
      std/js/Lib.hx

+ 8 - 0
std/js/Lib.hx

@@ -34,6 +34,14 @@ class Lib {
 		js.Syntax.code("debugger");
 		js.Syntax.code("debugger");
 	}
 	}
 
 
+	/**
+		Inserts an `import` expression that loads JavaScript object from
+		a module or file specified in the `module` argument.
+	**/
+	public static inline function dynamicImport(module:String):js.lib.Promise<Dynamic> {
+		return js.Syntax.code("import({0})", module);
+	}
+
 	/**
 	/**
 		Display an alert message box containing the given message.
 		Display an alert message box containing the given message.
 		@deprecated Use Browser.alert() instead.
 		@deprecated Use Browser.alert() instead.