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-relay-rebind

v0.1.0

Published

Component-scope state management for Relay modern & React.

Downloads

16

Readme

React Relay Rebind Travis npm-version Chat

React relay rebind is a component-scope state management for Relay modern & React.

React-Relay-Rebind is a local state managment for React components which use Relay. Focus of React Relay Rebind is to handle data resolved with Relay mutations and provide it to a component. Component will recieve a state prop for each rebinded mutation. The API declaratively passes down state to components thus simplifying the data flow. The common usecase is non-persistent/local data (e.g UI state) which does not belong and does not deserve to be mixed with persistent data.

⚠️ Warning: Do not use in production! RRR is highly experimental, please stand by until 1.0.0 is released.

Roadmap to production

  • [ ] Automagically provide dispatch to commitMutation
  • [ ] Simplify state configuration
  • [ ] Subscribe to specific piece of state
  • [ ] Optional state alias

Installation

Yarn

$ yarn add react-relay-rebind

NPM

$ npm install --save react-relay-rebind

or build from source

$ git clone react-relay-rebind
$ cd react-relay-rebind && yarn install
$ yarn run build

Usage

Provide dispatch to the commitMutation

import { commitMutation } from 'react-relay-rebind';

const mutation = graphql`
  mutation LoginMutation($input: LoginInput!) {
    login(credentials: $input) {
      errors {
        username
        password
      }
    }
  }
`;

const loginMutation = (environment, input, dispatch) => { // dispatch is passed as the last argument
  commitMutation(
    environment,
    {
      mutation,
      variables: input,
    },
    dispatch // provide dispatch to the the commitMutation
  );
}

export default loginMutation;

Rebind mutations with the component

import { rebind } from 'react-relay-rebind';
import { loginMutation } from './loginMutation';

class MyComponent extends React.component {

  handleSubmit(){
    this.props.mutations.login(this.props.relay, this.state);
  }

  render(){
    const { errors } = this.props.login;
    const usernameClassname = errors.username ? 'has-error' : '';
    const passwordClassname = errors.password ? 'has-error' : '';

    return (
       <div>
        <input
          className={usernameClassname}
          name="username"
          type="text"
          onChange={ e => this.setState({ username: e.target.value() }) }
          value={username} />
        <br/>
        <input
          className={passwordClassname}
          name="password"
          type="password"
          onChange={ e => this.setState({ password: e.target.value() }) }
          value={password} />
        <br/>
        <input type="submit" onClick={this.handleSubmit} value="Login"/>
      </div>
  }
}

const states = {
  login: {
    mutation: LoginMutation,
    initialState: {
      errors: {
        username: null,
        password: null,
      },
    },
  },
};
export default rebind(states)(MyComponent);

API Documentation

rebind(states)(component): Component

When rebinding a component you must provide states that are to be binded with the component.

states: Object

Must contain a configuration object { mutation: <mutation function>, initialState: <any> } for each mutation.

commitMutation(environment, config, dispatch)

Commits a mutation and dispatches resolved data as props to a component to whom mutation is rebinded to.

More detailed documentation forthcoming

Contributing

Contributions are welcomed! It's suggested to create an issue beforehand to shed some light to others on what kind of change you are working on. Fork, improve & create a pull request.

Development

Use yarn run lint to run a lint

Use yarn run test:cover to run tests

Please build locally before submitting a PR.

Contributors

Backers