New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce use of globals in http and services classes #3349
Comments
|
|
As long as it's only one, I'm not too worried. For example, http and fetch need a revamp, see #2889 |
It's not a huge deal, but I do find it a little distracting to have a global object as a main entry point. On first read of client code these end up looking like local objects. |
You can always import the library with a prefix. |
Please consider using imports with prefixes. Also, if it helps, users can import libraries with
|
"On first read of client code" was referring to code I didn't write. Anyway, it's not a huge deal. I logged this because @Hixie asked me to. :) |
I asked you to because you complained about it. :-) Given that http/fetch are already covered by #2889, is the only issue here that |
I just thought it was a strange practice to publish unscoped global objects and free-functions from the services classes. But if that's idiomatic Dart, then this should probably be closed. FWIW, in the case of imageCache.load(), I would have expected something more like ImageCache.default.load() (or ImageCache.instance.load() if it's a singleton). For rootBundle.load(), I would have expected AssetBundle.root.load(). And so on. |
Ah, I see what you mean. We did consider that. We ended up the way we have it because |
Do we intend to take any action here? If so, can we enumerate the actions in a task list in the issue description? If not, let's close. FWIW, the http library was designed to be imported with a prefix. Putting that level of control into our users' hands has worked out. For very simple cases, you don't want to dirty your code with prefixes. For more complex code, the developer gets to pick a relevant prefix name. Not all libraries are designed to be imported with a possible prefix, though. |
Let's close. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Currently several services publish global objects. For example,
asset_bundle.dart
publishesrootBundle
.http.dart
publishes a long list of global functions likeget
andpost
.These global objects and functions should be scoped to classes to avoid namespace issues.
The text was updated successfully, but these errors were encountered: