englercj / resource-loader

A middleware-style generic resource loader built with web games in mind.
http://englercj.github.io/resource-loader/
MIT License
424 stars 77 forks source link

Add support for multiple urlResolver functions #143

Closed bigtimebuddy closed 4 years ago

bigtimebuddy commented 4 years ago

Changed

I tried to keep the API as simple as possible and this is probably the most conservative approach, however, but I think it could also make sense to have a resolve function that works like use and internally the loader maintains instances.

const loader = new Loader();
loader.resolve(s => s.replace('{LANG}', 'en-US'));

Whatever you think is best.

englercj commented 4 years ago

Thanks for putting this together Matt, I really appreciate it.

I'm OK starting with the simplicity of just a list of resolvers. I do think we should just make the API be an array always though. Otherwise the usage for a user who wants to add a resolver involves checking if it an array or not before adding theirs. It would be easier to just always be an array so anyone can just push onto it.

One other piece of feedback, is I'd also rather hide it behind a function that adds a resolver. That way if down the road we want to add priority or something like middleware, we can do it in a backwards compatible way (add a param) rather than switch to a function at that time and do weird gymnastics to make an array property work. Maybe just addUrlResolver and make the property private?

bigtimebuddy commented 4 years ago

Sounds good and agreed. I can adjust this to accommodate that feedback.

bigtimebuddy commented 4 years ago

Okay I removed urlResolver and replaced with a addUrlResolver method that takes the function as a single argument.