Skip to content

Commit

Permalink
Fix scala.js deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Dec 17, 2020
1 parent af69228 commit 7de0612
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.11 (TBA)
* Packaging / infrastructure improvements:
* [npm package](https://www.npmjs.com/package/kaitai-struct-compiler/) now returns the compiler object itself instead of constructor function ([#222](https://github.com/kaitai-io/kaitai_struct_compiler/pull/222))

# 0.9 (2020-10-16)

* New targets support:
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ lazy val buildNpmJsFileTask = Def.task {
|
|$compiledFileContents
|
|return exports.io.kaitai.struct.MainJs;
|return exports.MainJs;
|
|}));
""".stripMargin
Expand Down
15 changes: 8 additions & 7 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,24 @@ Our [examples repository](https://github.com/kaitai-io/kaitai_struct_examples) c

## Plugging in

> :information_source: Before the version 0.11.0 the `kaitai-struct-compiler` module returned a _compiler constructor_ (called `KaitaiStructCompiler`) and you used it as `new KaitaiStructCompiler()`, but since 0.11.0 release this is the _compiler object_ itself and using `new` is not required anymore
We publish the compiler as an [UMD module](https://github.com/umdjs/umd), so it works from various environments, including server-side (eg. node) and client-side (eg. web browser) ones.

Note: currently we don't publish the compiler as standard ES module. This will probably change in the future. If you need ES module please comment on [this issue](https://github.com/kaitai-io/kaitai_struct/issues/180).

### node

```javascript
var KaitaiStructCompiler = require("kaitai-struct-compiler");
var compiler = new KaitaiStructCompiler();
var compiler = require("kaitai-struct-compiler");
```

### browser using script tags

```html
<script src="node_modules/kaitai-struct-compiler/kaitai-struct-compiler.js"></script>
<script src="node_modules/kaitai-struct-compiler/kaitai-struct-compiler.js"></script>
<script>
var compiler = new KaitaiStructCompiler();
var compiler = KaitaiStructCompiler;
</script>
```

Expand All @@ -78,14 +79,14 @@ var compiler = new KaitaiStructCompiler();
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
<script>
requirejs.config({
requirejs.config({
paths: {
'kaitai-struct-compiler': 'node_modules/kaitai-struct-compiler/kaitai-struct-compiler'
}
});
require(['kaitai-struct-compiler'], function(KaitaiStructCompiler){
var compiler = new KaitaiStructCompiler();
require(['kaitai-struct-compiler'], function(compiler){
// ...
});
</script>
```
Expand Down
2 changes: 2 additions & 0 deletions js/src/main/scala/io/kaitai/struct/JavaScriptImporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package io.kaitai.struct

import scala.scalajs.js
import scala.scalajs.js.Promise
import scala.scalajs.js.annotation.JSGlobal

@js.native
@JSGlobal
class JavaScriptImporter extends js.Object {
def importYaml(name: String, mode: String): Promise[js.Object] = js.native
}
4 changes: 2 additions & 2 deletions js/src/main/scala/io/kaitai/struct/MainJs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.scalajs.js
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.annotation.JSExport
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}

@JSExport
@JSExportTopLevel("MainJs")
object MainJs {
KSVersion.current = Version.version

Expand Down

0 comments on commit 7de0612

Please sign in to comment.