Capacitor: feat: Plugins wrapper for Angular

Created on 23 Jan 2020  路  5Comments  路  Source: ionic-team/capacitor

Feature Request

Describe the Feature Request

Services wrapper for Plugins on Angular (or other Frameworks) are not available. Preventing dependency injection and good testing.

Platform Support Requested

  • [ ] Android
  • [ ] iOS
  • [ ] Electron
  • [ ] Web

Describe Preferred Solution

Libraries for main frameworks (Angular, React, Vue) should be released, providing wrapping service to be able to inject the plugins in other classes to allow for testing and better maintainability (lazy loading, code analysis...)

Related Code

Service Example

Additional Context

I don't know if it is the right repository to post this issue, but I could not think of another one.

enhancement feature request

Most helpful comment

In the interim, I wouldn't go to the extreme of creating a bunch of boring injectable services just in order to test your code.

You can just replace the items on Plugins as such: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L11-L25

Use them in your test the usual way: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L34-L38

And just keep your code using the objects on Plugins the way that it is: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.ts#L17-L24

No services needed.

Totally agree that it would be nice to have them, though. It would make the testing more "natural", but it certainly isn't a requirement in many cases.

All 5 comments

Issues tagged with feature request are closed but tracked for reactions to gauge interest.

My opinion: Since Capacitor is framework agnostic, I think this should be a separate project/repo as it was done with capacitor react hooks https://github.com/ionic-team/ionic-react-hooks

I agree with you, it should be a separate project but I did not find a better place to talk about the feature.

I also wanted to make sure that it did not already existed as I took sometime to look for it but could not find anything on the web.

It seems a great idea. I just started a new project and it's boring to wrap every single plugins into an Angular services just in order to test my code.

In the interim, I wouldn't go to the extreme of creating a bunch of boring injectable services just in order to test your code.

You can just replace the items on Plugins as such: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L11-L25

Use them in your test the usual way: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.spec.ts#L34-L38

And just keep your code using the objects on Plugins the way that it is: https://github.com/ionic-team/iv-training-starter/blob/master/src/app/app.component.ts#L17-L24

No services needed.

Totally agree that it would be nice to have them, though. It would make the testing more "natural", but it certainly isn't a requirement in many cases.

@kensodemann Thanks, I don't know why I thought they were const.

But finally, I start to love my injectable services (it's maybe my OCD side). I think, that to have my plugins injected in the constructor, is more readable/maintainable to know what a component does.

Was this page helpful?
0 / 5 - 0 ratings