Closed hdennen closed 5 years ago
The reason is because this library doesn't want to be a resource caching and management system, just a loader. You shouldn't use this library for anything except the actual mechanism of loading data. All caching, resource management, knowing what is loaded and what isn't, deciding what to load, etc, should all exist as logic outside of this library.
The philosophy here is that once you've decided what to load, you fill a loader with requests and trigger it. If you're adding a name 2 times, then your higher-level logic is flawed and incorrectly had a duplicate in it.
As a more concrete statement, your project should have a Resource Manager that stores resources and manages their lifetime. When it decides something needs to be loaded from a remote source, only then does it create a loader and load them. It may have many loaders going at once, or only one. Up to you. Maybe it would be worthwhile for me to build a library that does that for people, built on top of this library.
@englercj it would be a good idea to make this more explicit up-front, perhaps in the main project readme. It is definitely unexpected behavior to folks coming new to the project and caused me a lot of debugging and googling to figure out what was going on.
My expectation was that if I requested loading an existing resource, the loader would simply queue it and immediately fire an onLoad once the loader starts just like a browser would with a dom node. I understand why you're not implementing that feature, but it is odd without the context you just provided.
(and thanks for this project - I really appreciate your work!)
I added this to the readme in the v4 typescript
branch.
Hi there,
This might be a feature request but just a question for now.
What's the reasoning behind throwing an error for resources that have already been added? https://github.com/englercj/resource-loader/blob/6d00e3a721a7b6f6befbfe0b61575bf37d309019/src/Loader.js#L372
From what I can tell there are 2 possible scenarios: one in which the resource is still outstanding and another in which the resource is complete.
In our system we load assets just in time, and can potentially hit both of these scenarios.
I've accounted for them in our system, but it occurs to me that the library could (potentially should?) be able to handle a scenario where the same asset is added more than once.
Just curious you thoughts on this. If I can make time I could potentially offer a PR for this functionality.