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-value-link

v1.0.1

Published

An alternative to React's LinkedStateMixin

Downloads

65

Readme

ValueLink

An alternative to React's LinkedStateMixin for two way data bindings

Advantages over LinkedStateMix

  • Support for binding any data object and not necessarily the component's state
  • Deep path based data bindings
  • Not a mixin so it just works with ES6 style React

Use it

Install with npm

npm install --save react-value-link

...then require it (assumes a frontend module bundler)

var ValueLink = require('react-value-link');

Or directly include on the page

<script type="text/javascript" src="react-value-link.js"></script>

API

ValueLink(data, onDataChange)

Returns a link associated to data

Arguments

data - object whose constituent values will be binded to <input> elements
onDataChange - callback called when <input> values change or when requestChange() is called explicity. It receives the changed data as first argument. onDataChange is where you would usually update the store, trigger an action or mutate the component's state

link

A functor used to create bindings or futher nested links. Every link has an associated path. The link returned by ValueLink has an empty path and directly points to data

A link is like ReactLink and similarly can be passed in the valueLink prop to React <input> elements to "bind" them with data at the associated path

<input ... valueLink={link} />

link(p1, [p2, [p3, [...]]])

Extends the path from link with p1, p2, p3, ... in that order and returns another link based of the extended path

Arguments

p1, p2, p3, ... - string or integer property names

This is used to create nested links

contactLink = link('contact');
...
nameLink    = contactLink('name');

link.value

Is the value within data at this link's path or null if there are missing objects in the path

link.requestChange(newValue)

Sets newValue at this link's path within data and calls onDataChange. Any missing objects in the path are automatically created if necessary

link.onChange

Since React 15 deprecated ReactLink, <input> components no longer support the valueLink prop. You can still use this library with React 15 by passing the value and onChange props seperately

<input ... value={link.value} onChange={link.onChange} />

link.handleChange

A hook to intercept a requestChange call on this link. This is good for validating, transforming or invoking a related action.

link.handleChange must be assigned a function accepting two arguments.

link.handleChange = function(newValue, change) {
    ...

    change(newValue);
};
Arguments

newValue - value passed to requestChange()
change - a function to set newValue or any other substitute in data and then invoke the onDataChange callback. You may decide to not call change at all in which case no changes are made to data and onDataChange is not invoked.

Example

var Hello = React.createClass({
   // unlike LinkedStateMixin, ValueLink is not a mixin
   getInitialState: function() {
       return { 
           values: {
             list: [
               { type: "translateX", x: 10 },
               { type: "scaleX", x: 1.2 }
             ]
           }
         };
   },
   render: function() {
       var that = this;

       var link = ValueLink(this.state.values, function(values) { that.setState({values: values}) } );

       // a partial valueLink binding which can be sent (as props) to child components that understand only a sub portion of the data structure
       var partial = link('list');
     
       return (
         <div>
           {
             this.state.values.list.map(function(item, i) {
               return (
                 <div>
                   <input valueLink={partial(i)('type')} />
                   <input valueLink={link('list', i, 'x')} />
                 </div>
               );
             })
           }
           <pre>{JSON.stringify(this.state)}</pre>
         </div>
       );
   }
});

React.render(<Hello name="World" />, document.body);

License - WTFPL

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2015 WebEngage <geeks {at} webengage.com>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.