Skip to content

Commit

Permalink
refactor how getter of functions is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
a14n committed Jul 9, 2024
1 parent 1216e03 commit 5972ce5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 61 deletions.
28 changes: 12 additions & 16 deletions lib/src/generated/image_overlay/map_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,26 @@ 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?;
}

@JS('getTile')
external Element? _getTile(Point tileCoord, num zoom, Document ownerDocument);
Element? Function(Point tileCoord, num zoom, Document ownerDocument)
get getTile =>
// ignore: unnecessary_lambdas
(tileCoord, zoom, ownerDocument) =>
_getTile(tileCoord, zoom, ownerDocument);
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);
}

@JS('releaseTile')
external void _releaseTile(Element? tile);
void Function(Element? tile) get releaseTile =>
// ignore: unnecessary_lambdas
(tile) => _releaseTile(tile);
void set releaseTile(
void Function(
Element? tile,
Expand Down
31 changes: 12 additions & 19 deletions lib/src/generated/image_overlay/projection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,25 @@ 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?;
}

@JS('fromLatLngToPoint')
external Point? _fromLatLngToPoint(LatLngOrLatLngLiteral latLng,
[Point? point]);
Point? Function(LatLngOrLatLngLiteral latLng, [Point? point])
get fromLatLngToPoint =>
// ignore: unnecessary_lambdas
(latLng, [point]) => _fromLatLngToPoint(latLng, 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?;
}

@JS('fromPointToLatLng')
external LatLng? _fromPointToLatLng(Point pixel, [bool? noClampNoWrap]);
LatLng? Function(Point pixel, [bool? noClampNoWrap]) get fromPointToLatLng =>
// ignore: unnecessary_lambdas
(pixel, [noClampNoWrap]) => _fromPointToLatLng(pixel, noClampNoWrap);
void set fromPointToLatLng(
LatLng? Function(
Point pixel, [
Expand Down
48 changes: 22 additions & 26 deletions tool/generate_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,24 +525,21 @@ 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?;
}
@JS('fromLatLngToPoint')
external Point? _fromLatLngToPoint(LatLngOrLatLngLiteral latLng, [Point? point]);
Point? Function(LatLngOrLatLngLiteral latLng, [Point? point]) get fromLatLngToPoint =>
// ignore: unnecessary_lambdas
(latLng, [point]) => _fromLatLngToPoint(latLng, 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?;
}
@JS('fromPointToLatLng')
external LatLng? _fromPointToLatLng(Point pixel, [bool? noClampNoWrap]);
LatLng? Function(Point pixel, [bool? noClampNoWrap]) get fromPointToLatLng =>
// ignore: unnecessary_lambdas
(pixel, [noClampNoWrap]) => _fromPointToLatLng(pixel, noClampNoWrap);
void set fromPointToLatLng(LatLng? Function(
Point pixel, [
bool? noClampNoWrap,
Expand All @@ -569,23 +566,22 @@ 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?;
}
@JS('getTile')
external Element? _getTile(Point tileCoord, num zoom, Document ownerDocument);
Element? Function(Point tileCoord, num zoom, Document ownerDocument) get getTile =>
// ignore: unnecessary_lambdas
(tileCoord, zoom, ownerDocument) => _getTile(tileCoord, zoom, ownerDocument);
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);
}
@JS('releaseTile')
external void _releaseTile(Element? tile);
void Function(Element? tile) get releaseTile =>
// ignore: unnecessary_lambdas
(tile) => _releaseTile(tile);
void set releaseTile(void Function(
Element? tile,
) releaseTile) => setProperty('releaseTile'.toJS, releaseTile.toJS);
Expand Down

0 comments on commit 5972ce5

Please sign in to comment.