Skip to content
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

feat: accept function values as valid instances #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

esroyo
Copy link

@esroyo esroyo commented Nov 19, 2022

There is a lot of JavaScript/browser functionality that comes just shaped as a function and not an object/instance: fetch, setTimeout/clearTimeout, atob/btoa, requestIdleCallback, etc. It seems handy to be able to inject function values on provisions. Does it feel ok? Any thoughts?

interface Fetch {
    (input: RequestInfo, init?: RequestInit): Promise<Response>;
}
const customFetch: Fetch = /* custom implementation */;
class HttpClient { 
    constructor(readonly fetchImpl: Fetch) {}
}

const injector = new Injector([provide(reify<Fetch>(), () => customFetch), provide(HttpClient)]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant