Danny Tuppeny Danny Tuppeny - 1 year ago 117
Dart Question

How can I interop with existing JS objects?

I'm trying to write Dart code that will generate a rough equivalent of this:

var disposable = vscode['commands'].registerCommand(
function () {
vscode['window'].showInformationMessage('Hello World!');

The variables
are both globals available in the JavaScript which is executing my Dart (which is being compiled to JS with the Dart Dev Compiler).

I'm happy for context/vscode to be completely untyped for now, but I'm struggling to bend the JS package to output code like this (eg. if I put @JS() on a stub
, I get

Answer Source

You can use the base dart:js features

Note that context happens to be dart's name for the javascript context.

var disposable = context['vscode']['commands'].callMethod('registerCommand', [
    () {
        context['vscode']['window'].callMethod('showInformationMessage', ['Hello World!']);
context['context']['subscriptions'].callMethod('push', [disposable]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download