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

inferno-fluxible

v3.1.10

Published

Connector for inferno-js and fluxible-js.

Downloads

63

Readme

inferno-fluxible

Connector for inferno-js and fluxible-js. See demo.

Install

npm i -s inferno-fluxible fluxible-js redefine-statics-js

Usage

Initialize store

import { initializeStore } from 'fluxible-js';

initializeStore({
  initialStore: {
    user: {
      name: 'Test User'
    },
    anotherState: 'value'
  }
});

// rest of the app.

Before you render your app, you MUST call initializeStore. It expects an object as the only parameter, the object have a required property called initialStore which will be used as the initial value of the store.

There's also the optional property called persist which MUST also be an object containing two required properties. Learn more about fluxible-js.

:new: Connecting your components to the store

import { mapStatesToProps } from 'inferno-fluxible';

class MyComponent extends Component {
  render() {
    return (
      <div>
        <p>{this.props.user.name}</p>
      </div>
    );
  }
}

export default mapStatesToProps(MyComponent, states => {
  return {
    user: state.user
  };
});

mapStatesToProps has two parameters. (1) The component itself. (2) A callback function that must return the states you want to be available as props in that component.

:new: Updating the store

You can choose between using the event bus or calling updateStore directly from the component.

Using updateStore

import { updateStore } from 'fluxible-js';
import { mapStatesToProps } from 'inferno-fluxible';

class MyComponent extends Component {
  handleClick = () => {
    updateStore({
      anotherState: 'newValue'
    });
  };

  render() {
    return (
      <div>
        <p>{this.props.user.name}</p>
        <button onClick={this.handleClick}>Click me</button>
      </div>
    );
  }
}

export default mapStatesToProps(MyComponent, states => {
  return {
    user: state.user,
    anotherState: state.anotherState
  };
});

You can also build a function yourself that would perform what you need to do.

import { updateStore } from 'fluxible-js';
import { mapStatesToProps } from 'inferno-fluxible';
import { doSomething } from '../mutations';

class MyComponent extends Component {
  render() {
    return (
      <div>
        <p>{this.props.user.name}</p>
        <button onClick={doSomething}>Click me</button>
      </div>
    );
  }
}

export default mapStatesToProps(MyComponent, states => {
  return {
    user: state.user,
    anotherState: state.anotherState
  };
});

This is better compared to how connect used to do it. This is more flexible, manageable, and performant. You don't need to make a lot of function calls when you can simply import updateStore and getStore pretty much wherever you want. The only purpose of mapStatesToProps provided by inferno-fluxible is to make sure that the components receive the latest store when the store is updated.

Using the event bus

Somewhere in your source code, ideally before emitting this event:

import { addEvent, updateStore } from 'fluxible-js';

addEvent('my-event', payload => {
  console.log(payload);

  updateStore({
    anotherState: payload
  });
});

On your component:

import { emitEvent } from 'fluxible-js';
import { mapStatesToProps } from 'inferno-fluxible';

class MyComponent extends Component {
  handleClick = () => {
    emitEvent('my-event', 'newValue');
  };

  render() {
    return (
      <div>
        <p>{this.props.user.name}</p>
        <button onClick={this.handleClick}>Click me</button>
      </div>
    );
  }
}

export default mapStatesToProps(MyComponent, states => {
  return {
    user: state.user,
    anotherState: state.anotherState
  };
});

Contributing

Discussions, questions, suggestions, bug reports, feature request, etc are all welcome. Just create an issue. Just ensure that you are responsive enough.


Created with :heart: by April Mintac Pineda.