Skip to content

Commit

Permalink
Integrate objectbox-js & objectbox-dart - make webpack export as a gl…
Browse files Browse the repository at this point in the history
…obal object (namespace)
  • Loading branch information
vaind committed Dec 31, 2021
1 parent 0208e9c commit 3555002
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 4 deletions.
10 changes: 9 additions & 1 deletion objectbox-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
This is a very basic ObjectBox implementation for JavaScript/TypeScript, based on IndexedDB instead of the native objectbox-c API.

### Build and copy to objectbox-dart

The following code builds TypeScript files into `build` folder, uses `webpack` to create a single JS,
copies the JS (and sourcemap) to `../objectbox/lib/`, and generates dart binding code in `../objectbox/lib/src/web/`.
```
```shell
npm run build:main
npm run install
npm run generate:dart
```

Or run a single action to do it all:
```shell
npm run all:dart
```

### Notes and useful links about the compilation/integration:

* modules are not supported, we need to compile to a single JS file (using `webpack`)
* example: https://github.com/google/chartjs.dart/
* example: https://github.com/matanlurey/dart_js_interop
* modules issue: https://github.com/dart-lang/sdk/issues/25059

### IndexedDB resources

* https://developers.google.com/web/ilt/pwa/working-with-indexeddb
* https://www.tutorialspoint.com/html5/html5_indexeddb.htm
* https://javascript.info/indexeddb
1 change: 1 addition & 0 deletions objectbox-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build:module": "tsc -p tsconfig.module.json",
"install": "cp build/objectbox.js* ../objectbox/lib/",
"generate:dart": "cd build/main/lib && dart_js_facade_gen --destination=../../../../objectbox/lib/src/web/ number.d.ts",
"all:dart": "run-p build:main && run-p install && run-p generate:dart",
"fix": "run-s fix:*",
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:lint": "eslint src --ext .ts --fix",
Expand Down
2 changes: 2 additions & 0 deletions objectbox-js/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ module.exports = {
output: {
filename: 'objectbox.js',
path: path.resolve(__dirname, 'build'),
library: 'objectbox',
libraryTarget: 'window'
},
};
2 changes: 1 addition & 1 deletion objectbox/lib/objectbox.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objectbox/lib/objectbox.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion objectbox/lib/src/web/number.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@JS()
@JS('objectbox')
library number;

import "package:js/js.dart";
Expand Down
1 change: 1 addition & 0 deletions objectbox/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies:
ffi: ^1.0.0
meta: ^1.3.0
path: ^1.8.0
js: ^0.6.3

dev_dependencies:
build_runner: ^2.0.0
Expand Down

0 comments on commit 3555002

Please sign in to comment.