Interaction with Js began with the package : js . It was built using window.postMessage .
Dart: js was later added to improve performance and reduce the size of the compiled js file. The main objectives were:
- area removal and manual life cycle management
- avoiding noSuchMethod so that the compilation size is as small as possible
- renaming objects to make the API more understandable
Once dart: js was ready, package: js was rewritten to use dart: js under the cover.
package: js provides a simpler Api, which is achieved by increasing the size of js (because package: js uses dart: mirrors and noSuchMethod).
Here is the same as with the package: js and dart: js:
import 'package:js/js.dart' as js; main() { var pixi = new js.Proxy(js.context.PIXI.Stage, 0xffffff); var renderer = js.context.PIXI.autoDetectRenderer(400, 400); document.body.append(renderer.view); }
import 'dart:js' as js; main() { var pixi = new js.JsObject(js.context['PIXI']['Stage'], [0xffffff]); var renderer = js.context['PIXI'].callMethod('autoDetectRenderer', [400, 400]); document.body.append(renderer['view']); }
Alexandre Ardhuin
source share