mcollina / mcollina/single-user-cache
dynamically add new loader functions to Cache
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 40
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Hey, I think that being able to colocate data fetching and resolvers is a good pattern some times, so I tend to wrap the API with a conditional check (to dynamically register the loader), is this library open for a PR adding that functionality?
const loaderFactory = new Factory()
function addLoader<T, O>(name: string, fn: Batchfn<T, O>) {
loaderFactory.add(name, fn)
return async (loader: Cache, key: T): Promise<O> => {
if (!loader[name]) {
loader.prototype[name] = loaderFactory.Cache.prototype[name]
}
return await loader[name](key)
}
}
getFoo = addLoader(...)
getFoo(loader, id)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing Cache and Factory APIs and how loader functions are currently registered. Determine the intended behavior for conditional registration and the addLoader flow shown in the issue, then confirm that dynamically added loaders work without changing existing loaders.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100