Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MVCArray bindings are broken #65

Closed
dietmarebner opened this issue Dec 18, 2018 · 5 comments
Closed

MVCArray bindings are broken #65

dietmarebner opened this issue Dec 18, 2018 · 5 comments

Comments

@dietmarebner
Copy link

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 a14n closed this as completed in df2e53a Dec 24, 2018
@a14n
Copy link
Owner

a14n commented Dec 24, 2018

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

@dietmarebner
Copy link
Author

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
Copy link
Owner

a14n commented Jan 16, 2019

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
Copy link

drewwarren commented Jul 11, 2019

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.

Object instance, String eventName, handler([dynamic p1]));

@a14n
Copy link
Owner

a14n commented Jul 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants