JordanAdams / cerebro-npm

📦 Cerebro plugin to search NPM packages
MIT License
9 stars 3 forks source link

Use memoization and debunce #5

Closed lubien closed 7 years ago

lubien commented 7 years ago

Right now, every time we type a query on your plugin we make a call to NPM's API.

That means that if I type "koa" we'll call "k", "ko", "koa" requests. Let's pretend I type "koac" with the "c" as typo then I delete the "c".This will make "k", "ko", "koa", "koac", "koa" requests. Two "koa" requests.

Memoization can reuse already loaded result. Currently I'm memoizing requests for one minute in my projects just so minor problems like the above one doesn't happen.

Debounce can prevent unwanted requests (like "k", "ko") while user is typing.

If you don't mind I can make a PR

p-debounce memoize example

JordanAdams commented 7 years ago

Sounds good to me. If you're happy to PR this, feel free 🙂

Awesome work on cerebro-hex, I was planning on building that too 😄

lubien commented 7 years ago

Added on #4

I didn't knew you use Elixir too btw ^^