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

react-rx-flux

v1.0.0

Published

React binding for rxjs powered flux

Downloads

3

Readme

ci codecov downloads node npm MIT npm bundle size

react-rx-flux

React binding for rxjs powered flux.

Description

react-rx-flux implements flux architecture in a way similar to react-easy-flux package, but with a small difference - it uses rxjs under the hood.

Installation

As any other npm package react-rx-flux can be added to your project by following command:

npm i -S react-rx-flux

It requires any version of rxjs and react with new context API support as peer dependency, so it should be installed as well.

npm i -S rxjs react

API

createStorage(reducer)

createStorage function creates new storage attributes such as Provider, useStorage(), useStream() and useActionCreators() hooks. You can crete several storages for different kind of data or use single storage (redux-like-way).

const {
    Provider: ThemeProvider,
    useStorage: useTheme,
    useStream: useThemeStream,
    useActionCreators: useThemeActions
} = createStorage(themeReducer);

const {
    Provider: GlobalStateProvider,
    useStorage: useGlobalState,
    useStream: useGloabalStream,
    useActionCreators: useGlobalActions
} = createStorage(globalStateRedurec);

Provider

All storage data consumers should be wrapped with Provider component, created by createStorage() function. You can pass state prop to set initial storage state.

render(
    <ThemeProvider state={ initialTheme }>
        <GlobalStorageProvider state={ initialGlobalState }>
            <App />
        </GlobalStorageProvider>
    </ThemeProvider>,
    document.getElementById('app')
);

useStorage() / useStream(pipe, checksum)

To consume/interact with storage state component should use useStorage() hook. It returns array of two elements: current state and dispatch() function to dispatch actions.

const Button = ({ ... }) => {
    const [ theme ] = useTheme();

    // use theme to set component style
};
import { setTheme } from './themeActions.js';

const ThemeSelector = ({ ... }) => {
    const [ , dipatch ] = useTheme();
    const onSelect = theme => dispatch(
        setTheme(theme)
    );

    ...
}

Until this moment react-rx-flux shows the same functionality as react-easy-flux. But as we mentioned before, it uses rxjs under the hood. To feel its advantages special useStream() hook exist. This hook allows user to create his own stream and subscribe to it from his components. In code snippet below we're implementing simple selector.

import { map } from 'rxjs/operators';

const MyComponent = () => {
    const [ value ] = useStream([
        map(
            state => state.value
        )
    ], []);

    ...
}

useStream() hook consumes two parameters:

Why this hook is so interesting? It gives us an opportunity to use all power of rxjs, so we can implement our own selector functionality as we did before, or optimize rendering by checking changes...

const [ value ] = useStream([
    map(
        ({ value }) => value
    ),
    distinct()
])

...or even apply debouncing...

const [ value ] = useStream([
    map(
        ({ search }) => search
    ),
    debounce(() => interval(500))
])

...without any significant effort.

useActionCreators(actionCreatorsMap)

To bind action creators useActionCreators() hook can be used.

import { setTheme } from './themeActions.js';

const ThemeSelector = ({ ... }) => {
    // const [ , dipatch ] = useTheme();
    // const onSelect = theme => dispatch(
    //    setTheme(theme)
    // );
    const { setTheme: onSelect } = useActionCreators({ setTheme })

    ...
}