Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

support registering custom type mappings #27

Open
ErikGrimes opened this issue Oct 9, 2015 · 5 comments
Open

support registering custom type mappings #27

ErikGrimes opened this issue Oct 9, 2015 · 5 comments

Comments

@ErikGrimes
Copy link

It seems like in order to allow seamless consumption of elements written in JavaScript, there needs to be a way to register unknown JavaScript types so that they are converted to Dart objects. There's probably a relationship here to custom-element-apigen too.

@jakemac53
Copy link
Contributor

cc @jacob314

@jakemac53
Copy link
Contributor

Similar to how@CustomElementProxy works but that is just for elements, I assume what you want here is a general purpose thing for any JS Object?

@ErikGrimes
Copy link
Author

Correct. If users can register type mappings for any JsObject, then on the Dart side, anything that can comes out of Polymer can be converted to a Dart object instead of JsObject. If this is done when someone wraps a JavaScript element in custom-element-apigen, then no-one who uses that element should have to know it's a not natively Dart. I think :)

@ErikGrimes
Copy link
Author

Also, I'm not sure, but the new js interop may remove the need for this.

@jacob314
Copy link

jacob314 commented Oct 9, 2015

Here's an example of what this case should look like like with the new JS interop.
There is no proxying or wrapping. Essentially you define JavaScript interfaces specifying the shape of the JavaScript API you want to access from Dart and then you can access that interface on any JavaScript object passed to Dart where DOM objects are considered JavaScript objects.

import 'package:js/js.dart';

@Js
class AwesomeCustomElement {
  // all methods must be external.
  external someAwesomeMethod(foo);
  external String get someAwesomeGetter;
} 

void main() {
  AwesomeCustomElement element = querySelector("#yourElementId");
  element.someAwesomeMethod("hello");
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants