a14n / dart-google-maps

A library to use Google Maps JavaScript API v3 from Dart scripts.
Apache License 2.0
130 stars 66 forks source link

MVCArray bindings are broken #65

Closed dietmarebner closed 5 years ago

dietmarebner commented 5 years ago

Bindings for MVCArray expose three streams, i.e., onInsertAt, onRemoveAT, and onSetAt.

The first one is correct but the other two wrap the click event rather than 'remove_at' and 'set_at' respectively. This is in dart-google-maps/lib/src/google_maps_src.g.dart:2889.

There's a test for this in dart-google-maps/test/gmaps_test.dart but that doesn't actually fail if the event handlers don't get executed.

a14n commented 5 years ago

Thanks for filing an issue. _googlemaps-3.3.3 fixes it.

dietmarebner commented 5 years ago

Thanks, Alexandre.

I think there's something missing with the codecs business. remove_at and set_at take two arguments (index and previous element) and return a IndexAndElement. _codec32 only does ([dynamic]) → dynamic but not the two-argument version.

Something like the snippet below works but this looks like auto-generated code so this should probably fixed elsewhere.

class _Undefined { const _Undefined(); }

const _undefined = _Undefined();

final codecOneOrTwoArgFunction = FunctionCodec /<([dynamic, dynamic]) → dynamic>/( (f) => ([p$p1, p$p2 = _undefined]) { var result = p$p2 == _undefined ? f(codec9.decode(p$p1)) : f(codec9.decode(p$p1), codec9.decode(p$p2)); return codec9.encode(result); }, (f) => ([p$p1, p$p2 = _undefined]) { var args = [__codec9.encode(p$p1)]; if (p$p2 != _undefined) args.add(codec9.encode(p$p2)); var result = f is JsFunction ? f.apply(args) : Function.apply(f, args); return __codec9.decode(result); }, );

a14n commented 5 years ago

When MVCArray contains JsObject you should provide a codec at its creation to make it know how to encode/decode the elements. For instance:

MVCArray<LatLng>(elements: latlngList, codec: JsInterfaceCodec((o) => LatLng.created(o)));
drewwarren commented 5 years ago

As dietmarebner commented above subscribing to onRemoveAT and onSetAt are still broken. You can replicate this by attempting to run the tests for MVCArray:

pub run test -p chrome test/gmaps_test.dart ...

00:06 +2: MVCArray works                                                                                           
inserted at 0
00:06 +2 -1: MVCArray works [E]                                                                                    
  NoSuchMethodError: method not found: 'call'
  Receiver: Closure '_closure0'
  Arguments: [0, "aa"]
  ...

A potential culprit is that the handler in _Event.addListener only takes a single optional argument. It's very difficult to trace this with the code generation. https://github.com/a14n/dart-google-maps/blob/f4d7e0f8a149d0773df02aff5db2e05c0055d37b/lib/src/core/events/event.dart#L27

a14n commented 5 years ago

@drewwarren Thanks for your feedback. The issue should be addressed by 0cbd411 publish in version 3.4.1