npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-livequery

v0.3.7

Published

Provide LiveQuery to react component

Downloads

20

Readme

Provide LiveQuery (SQL-like) to react component

npm downloads

Todos Live Demo using redux-livequery library

Motivation

Redux provide a good way to manage the state for React apps, but it lacks query/aggregation operation to compose multiple state together to get the data we would like(If we take predux as database, then redux should have query-like operation to react component). And in reselect, you have to manually compose your data and put yout logic in different nested functions.

Redux-livequery can give you a SQL-like live query to help you group values from multiple redux state together. And It only subscribes the state you care about, therefore it could let you have a better render performance. Whenever the state you care about changes, the result function would be invoked. (Indeed, it decouples the direct-subscribe to redux store)

For example, if you have long long array(around 100~1000), when the state which you care about in array changes, the result function would be invoked, so you don't filter array for your component. By contrast, if the other states in array which you don't care about change, the result function would not be invoked. The both situiation above, you don't need filter operation in your result function (redux-livequery library use redux low level api(store.subscribe) instead). But in reselect, any state in array changes, the redux will always invoke your selector function and you always filter the array whether the state that you care about changes or not. What's more, the reselect didn't provide debounce functionality to optimize your UI render frequency. In some external action trigger redux update like websocket or socket.io, you may not easily get the the high performance UX.

So,redux-livequery provide debounce functionality to let you tune your UI render performance/frequency.

Install

This has peer dependencies of [email protected], redux and immutability-helper, which will have to be installed as well.

npm install --save redux-livequery (or yarn add redux-livequery)

Configuring The Store

import { livequeryEnhancer } from 'redux-livequery';
const enhancer = compose(
  livequeryEnhancer(),
  ....
  applyMiddleware(....),
);
export const store = createStore(rootReducer, initialState || {}, enhancer);

Example

rxQueryLeftJoin API Example

import { rxQueryLeftJoin } from 'redux-livequery';
...
  componentDidMount(){
    ...
    const selector0 = (state) => state.completeSet;
    const selector1 = (state) => state.task;
    const field0 = 'complete'; 
    const field1 = 'task';
    this.unsubscribe = rxQueryLeftJoin([selector0, selector1], [field0, field1], (completeTaskList) => {
      // equals SQL query:
      // SELECT * FROM complete LEFT JOIN task ON complete.id=task.id;
      console.log(`next:`, completeTaskList);
    },
    33 //debounceTime 33ms
    );
  }
  componentWillUnmount(){
    // unsubscribe the livequery
    this.unsubscribe();
  }

rxQueryInnerJoin API Example

import { rxQueryInnerJoin } from 'redux-livequery';
...
  componentDidMount(){
    ...
    const selector0 = (state) => state.completeSet;
    const selector1 = (state) => state.activeSet;
    const selector2 = (state) => state.task;
    const field0 = 'complete'; 
    const field1 = 'active';
    const field2 = 'task';
    this.unsubscribe = rxQueryInnerJoin([selector0, selector1, selector2], [field0, field1, field2], (completeAndActiveTaskList) => {
      // equals SQL query:
      // SELECT * FROM complete INNER JOIN active ON complete.id=active.id INNER JOIN task on task.id===complete.id
      console.log(`completeAndActiveTaskList:`, completeAndActiveTaskList);
    },
    33 //debounceTime 33ms
    );
  }
  componentWillUnmount(){
    // unsubscribe the livequery
    this.unsubscribe();
  }