question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: have `shouldRecompute` instead of custom equality function

See original GitHub issue

I would like to be able to provide a function:

shouldRecompute: (lastResult: T, lastArgs: Array<unknown>, newArgs: Array<unknown>) => boolean

instead of custom equality function. In my case, whether the result should be recomputed depends on the previous result.

Use case: I am building a calendar with monthly view. For input data (events etc.) and given date, I filter events and compute begin and end, which are first and last timestamp for that month. In shouldRecompute, I would like just to check if new date is between these two values. Alternative is to have a custom equality which would compare months of previous and new date argument, but this is pretty costly (in general they are unix timestamps).

In general, my opinion is that shouldRecompute is better than custom equality even for general case. Most of the time, arguments have different types, so custom equality ends up being a branchy if statement checking for types of arguments and performing duty.

With shouldRecompute, it would be possible to test all arguments at once, which is much easier to reason about.

E.g. before:

if (typeof a === 'string') {
  return a === b;
} else if (a instanceof Date) {
  return isSameMonth(a, b);
} else {
  ...
} 

after:

return lastArgs[0] === newArgs[0] && isSameMonth(lastArgs[1], newArgs[1]) && ...;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alamothecommented, May 16, 2019

I like the latest API but still doesn’t work for my case. How about just pass lastResult as a third argument? That won’t break anything since previous arguments are unchanged.

1reaction
alexreardoncommented, Oct 22, 2018

this seems like a reasonable path forward 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >
errors: feature request: nil-safe compares #6965 - golang/go
Frequently when writing tests, we end up comparing two error values, on of which may be nil. It would be useful to have...
Read more >
Should you build a feature for just one customer? - OpinionX
As a general rule, building your product based on feature requests results in more pain than progress. There are several reasons why you ......
Read more >
How we handle feature requests - Artlogic Support
How we review requests. Following our internal feature request meetings, viable requests are selected and then considered for inclusion in our development ...
Read more >
Feature request: Screen compare function - Atlassian
Scheme comparison is great, but I'd love to have sth. like a "Screen Compare" function. If 2 screens differ only by 1 custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found