isoos / service_worker

Service Worker API for Dart
https://pub.dartlang.org/packages/service_worker
BSD 3-Clause "New" or "Revised" License
36 stars 19 forks source link

Provide getter for delegate in ServiceWorkerRegistration #2

Closed Janamou closed 7 years ago

Janamou commented 7 years ago

Hi Istvan, thank you very much for the great library!

I am now implementing a Firebase cloud messaging to firebase-dart and in some point of the time, I would love to have a native JavaScript object for ServiceWorkerRegistration. The reason is, that I need to call the messaging.useServiceWorker() method in my wrapper which calls the useServiceWorker() from JavaScript but I need to have the JavaScript ServiceWorkerRegistration object - which is your facade.ServiceWorkerRegistration :-)

And it would be great to have the getter for _delegate. Then I can do this:

import 'package:service_worker/window.dart' as sw;

dynamic useServiceWorker(sw.ServiceWorkerRegistration registration) =>
      jsObject.useServiceWorker(registration.deletage);

Would it be a problem to have a getter for _delegate?

Thanks!

isoos commented 7 years ago

Exposed it as ServiceWorkerRegistration.jsObject in #d79a72

isoos commented 7 years ago

Thanks for bringing up this use case. I think exposing the JS Object should be the last resort, but in this specific integration it does provide a value that is hard to get around in other ways. I hope it can be the exception than the general pattern.

Janamou commented 6 years ago

@isoos Thanks a loooot for this! Works for me! :-)