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.

Proposal: improve `connectRange()` behavior

See original GitHub issue

Improve the refine() documentation

When you create a calendar widget (to refine with date ranges), you sometimes need to specify a lower bound without any upper bound (let’s say “Display all events from 26/01/2018”). A way to do so is to pass undefined as the upper bound:

refine([start, undefined])

I don’t think we’ve documented passing undefined anywhere (see refine() doc).

Actions:
  • Document that refine() accepts undefined as an unlimited bound

Consider supporting Infinity

For now, the refine() method only takes finite values. Passing -Infinity or Infinity to a range made sense at first to me (typeof Infinity === 'number'). It is however ignored by refine() and doesn’t trigger any refinements when provided. I think it should be supported since it is a number and should fall back to undefined internally.

The documentation doesn’t state that refine() only supports finite numbers.

Actions:
  • Specify in the refine() doc that it filters only with finite values OR
  • Support infinite values (process them as undefined internally)
  • (?) Log warnings when the refinement isn’t triggered

Future API improvements

As discussed with @samouss, it might be interesting to change refine(Array<number, number>) to an object refine({ min: number, max: number}) in a next major release. A reason behind this is that both values are optional. It also feels more natural to pass an object rather than a tuple (see range). If we decide to do so, we should also change the start method to a similar object.


Do you think these inputs are relevant? Should we take action?

TL;DR

  • refine() accepting undefined is not documented
  • refine() only accepts finite values (not Infinity and -Infinity)
  • Infinity and -Infinity should behave like undefined
  • We should consider passing an object to refine() instead of an array in the future

Related

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
francoischalifourcommented, Jan 29, 2018

Both arguments for supporting (or not) Infinity are valid. Dropping or adding complete support for infinite values is something we should consider in a next major release if it is to add breaking changes then.

I’m going to document the usage of undefined as a “no bound” value for refine() since this is a priority 🙂

1reaction
samousscommented, Jan 26, 2018

@bobylito Yes but IIRC when we worked on the connectRange recently we kept the Infinity value only for backward compatibility. At some point we should get rid of the Infinity initialisation for undefined. Because inside the rendering we don’t use those values, we transform them before the component creation.

https://github.com/algolia/instantsearch.js/blob/35a1da173a99decec253aa985b2ff8e60f9c872a/src/widgets/range-input/range-input.js#L42-L45

https://github.com/algolia/instantsearch.js/blob/3b659783cd659f82539d97aec2e3ca1e691797f5/src/widgets/range-slider/range-slider.js#L43-L53

Read more comments on GitHub >

github_iconTop Results From Across the Web

Let refine accept undefined to remove a selected value #2309
When implementing a connector like menu it's hard to know what to do to remove a value. The refine is implemented like a...
Read more >
rangeInput | InstantSearch.js - Algolia
An InstantSearch.js widget for selecting a numerical range using a minimum and maximum input.
Read more >
Class vrCollision | VRED Products 2021
The constructor of the vrCollision class. bool, isColliding() Checks if objects from the two lists are colliding. Inherited from vrAEBase.
Read more >
Nevada Test and Training Range Expansion of Stagecoach ...
lies just outside the live target areas and the proposed upgrade would connect Range 63C Complex to. Box Canyon.
Read more >
Gallagher Mobile Connect SDK for iOS - Developer Guide
If you attempt to access instance before configure() a fatal error will be thrown ... This is the standard behaviour for iOS applications....
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