All Projects → Magellol → reactive-search

Magellol / reactive-search

Licence: MIT license
Incremental search using React and RxJS

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to reactive-search

Rxjs In Action
Code sample repository
Stars: ✭ 117 (+680%)
Mutual labels:  reactive, rxjs
Redux Most
Most.js based middleware for Redux. Handle async actions with monadic streams & reactive programming.
Stars: ✭ 137 (+813.33%)
Mutual labels:  reactive, rxjs
React Eva
Effects+View+Actions(React distributed state management solution with rxjs.)
Stars: ✭ 121 (+706.67%)
Mutual labels:  reactive, rxjs
Rx Connect
Glue your state and pure React components with RxJS
Stars: ✭ 86 (+473.33%)
Mutual labels:  reactive, rxjs
redrock
Typesafe, reactive redux
Stars: ✭ 14 (-6.67%)
Mutual labels:  reactive, rxjs
Connective
agent-based reactive programming library for typescript
Stars: ✭ 98 (+553.33%)
Mutual labels:  reactive, rxjs
Beicon
Reactive Streams for ClojureScript
Stars: ✭ 133 (+786.67%)
Mutual labels:  reactive, rxjs
Watermelondb
🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
Stars: ✭ 7,996 (+53206.67%)
Mutual labels:  reactive, rxjs
rxrest
Reactive rest library
Stars: ✭ 33 (+120%)
Mutual labels:  reactive, rxjs
Awesome Reactive Programming
A repository for sharing all the resources available on Reactive Programming and Reactive Systems
Stars: ✭ 163 (+986.67%)
Mutual labels:  reactive, rxjs
Karet
Karet is a library that allows you to embed Kefir observables into React VDOM
Stars: ✭ 81 (+440%)
Mutual labels:  reactive, incremental
reactive-graphql
A GraphQL implementation based around RxJS, very well suited for client side only GraphQL usage
Stars: ✭ 58 (+286.67%)
Mutual labels:  reactive, rxjs
Example
Example project written using Marble.js framework
Stars: ✭ 57 (+280%)
Mutual labels:  reactive, rxjs
Rxviz
Rx Visualizer - Animated playground for Rx Observables
Stars: ✭ 1,471 (+9706.67%)
Mutual labels:  reactive, rxjs
Inferno Most Fp Demo
A demo for the ReactJS Tampa Bay meetup showing how to build a React+Redux-like architecture from scratch using Inferno, Most.js, reactive programmning, and various functional programming tools & techniques
Stars: ✭ 45 (+200%)
Mutual labels:  reactive, rxjs
Ayanami
🍭 A better way to react with state
Stars: ✭ 129 (+760%)
Mutual labels:  reactive, rxjs
Platform
Reactive libraries for Angular
Stars: ✭ 7,020 (+46700%)
Mutual labels:  reactive, rxjs
Dugong
Minimal State Store Manager for React Apps using RxJS
Stars: ✭ 10 (-33.33%)
Mutual labels:  reactive, rxjs
Marble
Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS.
Stars: ✭ 1,947 (+12880%)
Mutual labels:  reactive, rxjs
bassdrum
reactive, type safe components with preact and rxjs.
Stars: ✭ 44 (+193.33%)
Mutual labels:  reactive, rxjs

Build Status

Reactive search

React component allowing you to query some api "as-you-type". Out of the box, it takes care of debouncing input events for you, so you don't over query your api.

Table of Contents

Demo

Check out the demo. Please keep in mind that the component doesn't do any caching whatsoever, everything is up to you. In this demo, I've implemented a really basic redis caching to speed things up.

Installation

yarn add reactive-search

// Or via npm
npm i --save reactive-search

Quickstart

Here's a quick example of what it would look like if you were to use the component.

import ReactiveSearch from 'reactive-search';

export default function App() {
  return (
    <ReactiveSearch
      classes={['input', 'rounded-corner']}
      getUrlToRequest={searchTerm => `/search/${searchTerm}`}
      onResponse={response => console.log('Got response', response)}
      shouldRetryOnError={error => false}
      onFatalError={error => console.error('Big Bad Bug', error)}
    />
  );
}

Configure

The component offers a few props (some required) to allow you to customized some behaviours.

classes

Accepted Types: Default Value Required
Array [] false

The classes prop takes an array of strings and will join them to build the className string.

// Produces `className="input rounded-corner"`
<ReactiveSearch classes={['input', 'rounded-corner']} />

getUrlToRequest

Accepted Types: Default Value Required
Function None true

getUrlToRequest is a function that'll be called whenever an API call is about to be made. Your callback will receive the search term (after any filtering the component does).

function buildUrl(searchTerm) {
  return `http://fastest-api-in-the-world.com/search?s=${searchTerm}`;
}

<ReactiveSearch getUrlToRequest={buildUrl} />

Note: Your function will not be called if the value has been filtered out. ReactiveSearch trims and removes extraneous spaces before letting the input going through. If the output results in empty string, your callback will not be called.

Here's what it does under the hood:

this.input$
  .map(value => value.trim().toLowerCase().replace(/\s\s+/g, ' '))
  .filter(value => value.length) // Will not let through empty strings
  ...
  .switchMap((searchTerm) => {
    const url = getUrlToRequest(searchTerm);
    ...
  });

onResponse

Accepted Types: Default Value Required
Function None true

onResponse is a callback that'll be called whenever the API sent back a response. It'll receive whatever your fetch implementation returns from that call. Please keep in mind that this component uses by default the native fetch browser implementation. So still by default, a response with a status that is not 200 is still considered successful by the native fetch spec. This behaviour may differ if you're using a custom polyfill.

function handleResponse(response) {
  response.json().then((content) => {
    this.setState({ content });
  });
}

<ReactiveSearch onResponse={handleResponse} />

shouldRetryOnError

Accepted Types: Default Value Required
Function () => false false

Optional function you can pass to evaluate if an error you encountered somewhere in the pipeline of doing a request should be ignored. If your function returns true, the error is ignored and we subscribe again to events. If your function returns false, onFatalError will be called and no more further events will be dispatched.

function shouldRetryOnError(error) {
  return error.status < 500;
}

<ReactiveSearch shouldRetryOnError={shouldRetryOnError} />

The reason this exists is because this component uses the RxJS library and by default when an observable receives an error, it will unsubscribe and will not receive any further events. Think of shouldRetryOnError as a retry behaviour.

onFatalError

Accepted Types: Default Value Required
Function None true

onFatalError is the final callback that will be called when an unhandled error bubbles up. After this callback has been called, no more events will be dispatched and no more API requests will be made. You should use this to produce any warning for you and your users.

function fatalErrorHandler(error) {
  showErrorMessageToUser(error.message);
  log(error);
}

<ReactiveSearch onFatalError={fatalErrorHandler} />

Disclaimer

  • It's a BYOP (bring your own Promise) and BYOF (bring your own fetch) library.
  • This component doesn't perform any caching whatsoever. Client side/server side caching should be your responsibility.

Contribute

Contributions are welcome! Please open issues when you found a bug. If you wish to fix a bug, a pull request is necessary. The PR is required to pass the tests and the linter before being merged. If you wish to work on a new feature, open an issue and we'll talk about it.

# Run the test
- yarn run test

# Run the linter
- yarn run lint

# Watch changes
- yarn run watch

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].