1
votes

I'm using Parse.com as my server solution. I'm loading their framework.js in my dart.html header section.

First of all, everything(CRUD) works great running in Dartium. Now my goal is to make it work compiled to javascript as well.

First thing I need to do is make login work. The Parse JS for initialization and logging in is as follow:

Parse.initialize("appid", "appkey");

Parse.User.logIn("myname", "mypass", {
  success: function(user) {
    // Do stuff after successful login.
  },
  error: function(user, error) {
    // The login failed. Check error to see why.
  }
});

And here is my updated attempt in Dart. I'm not running with the minified option.

import 'dart:html';
import 'package:web_ui/web_ui.dart';
import 'package:js/js.dart' as js;

void main() {

  js.context.Parse.initialize("appid", "appkey");

  js.context.Parse.User.logIn("myname","mypass", js.map({
    "success": new js.Callback.once((user){
      print("success");
    }),
    "error": new js.Callback.once((user, error){
      print("error");
    }),
  }));
}

It's working great in Dartium and prints "success".

When compiled to javascript I get this error in Safari: JSON.stringify cannot serialize cyclic structures.

The full error in Google Chrome console looks like this:

Uncaught TypeError: Converting circular structure to JSON js.dart:1043
$.Proxy__forward js.dart:1043
$$.Proxy.noSuchMethod$1 js.dart:1033 (anonymous function)
$.main tabort.dart:21
$.main0 tabort.html_bootstrap.dart:8
$$._IsolateContext.eval$1 isolate_helper.dart:265
$.startRootIsolate isolate_helper.dart:89 (anonymous function)
tabort.html_bootstrap.dart.js:13949

Help, or pointing me in the right direction would be very appreciated!

EDIT: Downloaded the latest continuous build: 0.1.2_r22610. Now everything works!

1

1 Answers

2
votes

The Dart code corresponding to this JS code :

Parse.User.logIn("myname", "mypass", {
  success: function(user) {
    // Do stuff after successful login.
  },
  error: function(user, error) {
    // The login failed. Check error to see why.
  }
});

is :

js.context.Parse.User.logIn("myname", "mypass", js.map({
  'success': new js.Callback.once((user) {
    // Do stuff after successful login.
  }),
  'error': new js.Callback.once((user, error) {
    // The login failed. Check error to see why.
  })
}));

If you compile your Dart code to JS don't use the --minify option because of issue 9283.

EDIT : Your problem ( JSON.stringify cannot serialize cyclic structures ) should disappear starting from r22598 (see https://groups.google.com/a/dartlang.org/d/msg/misc/zZ8Sx5rojis/UddCmmnaYTkJ)