Skip to content

Commit

Permalink
Merge pull request #132 from Rexios80/add-missing-getters
Browse files Browse the repository at this point in the history
Fix issues with new js interop
  • Loading branch information
a14n authored Jul 9, 2024
2 parents 2971261 + 0e15616 commit 1216e03
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/src/generated/event/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ extension type event._(JSObject _) implements JSObject {
);
external static void trigger(
JSObject /*Object<null>*/ instance,
String eventName,
String eventName, [
JSAny? /*UNPARSED:...?*/ eventArgs,
);
]);
external static MapsEventListener addDomListener(
JSObject /*Object<null>*/ instance,
String eventName,
Expand Down
17 changes: 17 additions & 0 deletions lib/src/generated/image_overlay/map_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,30 @@ extension type MapType._(JSObject _) implements JSObject {
String? name,
Projection? projection,
});
Element? Function(
Point? tileCoord,
num? zoom,
Document? ownerDocument,
) get getTile {
final function = (getProperty('getTile'.toJS) as JSObject)
.callMethod('bind'.toJS, [this].toJS) as JSFunction;
return (tileCoord, zoom, ownerDocument) => function.callAsFunction(
null, tileCoord, zoom?.toJS, ownerDocument) as Element?;
}

void set getTile(
Element? Function(
Point tileCoord,
num zoom,
Document ownerDocument,
) getTile) =>
setProperty('getTile'.toJS, getTile.toJS);
void Function([Element? tile]) get releaseTile {
final function = (getProperty('releaseTile'.toJS) as JSObject)
.callMethod('bind'.toJS, [this].toJS) as JSFunction;
return ([tile]) => function.callAsFunction(null, tile);
}

void set releaseTile(
void Function(
Element? tile,
Expand Down
20 changes: 20 additions & 0 deletions lib/src/generated/image_overlay/projection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@ part of '../image_overlay.dart';

extension type Projection._(JSObject _) implements JSObject {
factory Projection() => JSObject() as Projection;
Point? Function(
LatLngOrLatLngLiteral latLng, [
Point? point,
]) get fromLatLngToPoint {
final function = (getProperty('fromLatLngToPoint'.toJS) as JSObject)
.callMethod('bind'.toJS, [this].toJS) as JSFunction;
return (latLng, [point]) =>
function.callAsFunction(null, latLng, point) as Point?;
}

void set fromLatLngToPoint(
Point? Function(
LatLngOrLatLngLiteral latLng, [
Point? point,
]) fromLatLngToPoint) =>
setProperty('fromLatLngToPoint'.toJS, fromLatLngToPoint.toJS);
LatLng? Function(
Point? pixel, [
bool? noClampNoWrap,
]) get fromPointToLatLng {
final function = (getProperty('fromPointToLatLng'.toJS) as JSObject)
.callMethod('bind'.toJS, [this].toJS) as JSFunction;
return (pixel, [noClampNoWrap]) =>
function.callAsFunction(null, pixel, noClampNoWrap?.toJS) as LatLng?;
}

void set fromPointToLatLng(
LatLng? Function(
Point pixel, [
Expand Down
1 change: 1 addition & 0 deletions lib/src/generated/marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import 'dart:async' show Stream, StreamController;
import 'dart:js_interop';
import 'dart:js_interop_unsafe' show JSObjectUnsafeUtilExtension;

import 'coordinates.dart' show LatLng, LatLngOrLatLngLiteral, Point, Size;
import 'event.dart' show MVCObject, MapsEventListener, event;
Expand Down
2 changes: 2 additions & 0 deletions lib/src/generated/marker/marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension type Marker._(MVCObject _) implements MVCObject {
external Marker([
MarkerOptions? opts,
]);
bool isDraggableDefined() => callMethod('getDraggable'.toJS) != null;

external static int get MAX_ZINDEX;
@JS('getAnimation')
external Animation? _getAnimation();
Expand Down
1 change: 1 addition & 0 deletions lib/src/generated/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import 'dart:async' show Stream, StreamController;
import 'dart:js_interop';
import 'dart:js_interop_unsafe' show JSObjectUnsafeUtilExtension;

import 'coordinates.dart'
show
Expand Down
2 changes: 2 additions & 0 deletions lib/src/generated/polygon/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extension type Circle._(MVCObject _) implements MVCObject {
external Circle.js([
JSAny? /*(Circle|CircleLiteral|CircleOptions)?*/ circleOrCircleOptions,
]);
bool isDraggableDefined() => callMethod('getDraggable'.toJS) != null;

@JS('getBounds')
external LatLngBounds? _getBounds();
LatLngBounds? get bounds => _getBounds();
Expand Down
2 changes: 2 additions & 0 deletions lib/src/generated/polygon/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension type Polygon._(MVCObject _) implements MVCObject {
external Polygon([
PolygonOptions? opts,
]);
bool isDraggableDefined() => callMethod('getDraggable'.toJS) != null;

@JS('getDraggable')
external bool _getDraggable();
bool get draggable => _getDraggable();
Expand Down
2 changes: 2 additions & 0 deletions lib/src/generated/polygon/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension type Polyline._(MVCObject _) implements MVCObject {
external Polyline([
PolylineOptions? opts,
]);
bool isDraggableDefined() => callMethod('getDraggable'.toJS) != null;

@JS('getDraggable')
external bool _getDraggable();
bool get draggable => _getDraggable();
Expand Down
44 changes: 44 additions & 0 deletions tool/generate_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ extension LatLngBoundsOrLatLngBoundsLiteral$Ext on LatLngBoundsOrLatLngBoundsLit
' external Circle.copy(Circle circle);',
' external Circle.copyLiteral(CircleLiteral circle);',
]);
customCode.add('''
bool isDraggableDefined() => callMethod('getDraggable'.toJS) != null;
''');
customDependencies.add('JSObjectUnsafeUtilExtension');

case 'Projection':
customDependencies.addAll([
Expand All @@ -521,10 +525,24 @@ extension LatLngBoundsOrLatLngBoundsLiteral$Ext on LatLngBoundsOrLatLngBoundsLit
customConstructors
.add('factory Projection() => JSObject() as Projection;');
customCode.add('''
Point? Function(
LatLngOrLatLngLiteral latLng, [
Point? point,
]) get fromLatLngToPoint {
final function = (getProperty('fromLatLngToPoint'.toJS) as JSObject).callMethod('bind'.toJS, [this].toJS) as JSFunction;
return (latLng, [point]) => function.callAsFunction(null, latLng, point) as Point?;
}
void set fromLatLngToPoint(Point? Function(
LatLngOrLatLngLiteral latLng, [
Point? point,
]) fromLatLngToPoint) => setProperty('fromLatLngToPoint'.toJS, fromLatLngToPoint.toJS);
LatLng? Function(
Point? pixel, [
bool? noClampNoWrap,
]) get fromPointToLatLng {
final function = (getProperty('fromPointToLatLng'.toJS) as JSObject).callMethod('bind'.toJS, [this].toJS) as JSFunction;
return (pixel, [noClampNoWrap]) => function.callAsFunction(null, pixel, noClampNoWrap?.toJS) as LatLng?;
}
void set fromPointToLatLng(LatLng? Function(
Point pixel, [
bool? noClampNoWrap,
Expand All @@ -551,11 +569,23 @@ extension LatLngBoundsOrLatLngBoundsLiteral$Ext on LatLngBoundsOrLatLngBoundsLit
'Document',
]);
customCode.add('''
Element? Function(
Point? tileCoord,
num? zoom,
Document? ownerDocument,
) get getTile {
final function = (getProperty('getTile'.toJS) as JSObject).callMethod('bind'.toJS, [this].toJS) as JSFunction;
return (tileCoord, zoom, ownerDocument) => function.callAsFunction(null, tileCoord, zoom?.toJS, ownerDocument) as Element?;
}
void set getTile(Element? Function(
Point tileCoord,
num zoom,
Document ownerDocument,
) getTile) => setProperty('getTile'.toJS, getTile.toJS);
void Function([Element? tile]) get releaseTile {
final function = (getProperty('releaseTile'.toJS) as JSObject).callMethod('bind'.toJS, [this].toJS) as JSFunction;
return ([tile]) => function.callAsFunction(null, tile);
}
void set releaseTile(void Function(
Element? tile,
) releaseTile) => setProperty('releaseTile'.toJS, releaseTile.toJS);
Expand Down Expand Up @@ -618,6 +648,20 @@ extension LatLngBoundsOrLatLngBoundsLiteral$Ext on LatLngBoundsOrLatLngBoundsLit
case 'DataGeometryCollection':
methods.removeWhere(
(e) => {'forEachLatLng', 'getType'}.contains(e.method.name));
case 'event':
final triggerMethod =
methods.firstWhere((e) => e.method.name == 'trigger');
final eventArgsParameter = triggerMethod.method.parameters
.firstWhere((e) => e.name == 'eventArgs');
triggerMethod.method.parameters.remove(eventArgsParameter);
triggerMethod.method.optionalParameters.add(eventArgsParameter);
case 'Marker':
case 'Polyline':
case 'Polygon':
customCode.add('''
bool isDraggableDefined() => callMethod('getDraggable'.toJS) != null;
''');
customDependencies.add('JSObjectUnsafeUtilExtension');
}
for (final method in methods) {
if (method.method.returnType.startsWith('JSPromise<') &&
Expand Down

0 comments on commit 1216e03

Please sign in to comment.