• This repository has been archived on 04/May/2020
  • Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

react pure render mixin for facebook/immutable-js library

react-immutable-render-mixin

Users are urged to use PureRenderMixin with facebook/immutable-js. If performance is still an issue an examination of your usage of Immutable.js should be your first path towards a solution. This library was created from experimentations with Immutable that were ultimately erroneous; improper usage of Immutable.js πŸ’©. Users should be able to achieve maximum performance simply using PureRenderMixin.

This library exposes 4 distinct options for immutable rendering:

  • Mixin for React.createClass support
  • HoC ( decorator ) for React.Component
  • shouldComponentUpdate function used by the mixin and HoC
  • shallowEqualImmutable function to allow custom shouldComponentUpdate implementations

This library when used as a mixin/decorator replaces the PureRenderMixin when using facebook/immutable-js library with React

This Mixin and HoC implements shouldComponentUpdate method using prop and state equality with Immutable.is().

We also expose the shallowEqualImmutable to allow developers to craft a custom shouldComponentUpdate method as needed.

Installation

npm i react-immutable-render-mixin

Usage as Mixin

import immutableRenderMixin from 'react-immutable-render-mixin';

React.createClass({
  mixins: [immutableRenderMixin],

  render: function() {
    return <div className={this.props.className}>foo</div>;
  }
});

Usage as a HoC

import React from 'react';
import { immutableRenderDecorator } from 'react-immutable-render-mixin';

class Test extends React.Component {
  render() {
    return <div></div>;
  }
}

export default immutableRenderDecorator(Test);

Usage as Decorator

import React from 'react';
import { immutableRenderDecorator } from 'react-immutable-render-mixin';

@immutableRenderDecorator
class Test extends React.Component {
  render() {
    return <div></div>;
  }
}

Usage with default shouldComponentUpdate

import React from 'react';
import { shouldComponentUpdate } from 'react-immutable-render-mixin';

class Test extends React.Component {
  constructor(props) {
    super(props);
    this.shouldComponentUpdate = shouldComponentUpdate.bind(this);
  }

  render() {
    return <div></div>;
  }
}

Usage with a custom shouldComponentUpdate

import React from 'react';
import { shallowEqualImmutable } from 'react-immutable-render-mixin';

class Test extends React.Component {
  shouldComponentUpdate(nextProps, nextState) {
    return !shallowEqualImmutable(this.props, nextProps) || !shallowEqualImmutable(this.state, nextState);  
  }

  render() {
    return <div></div>;
  }
}

Usage with <= ES5

Exports:

var immutableRenderMixin = require('react-immutable-render-mixin').default;

var immutableRenderDecorator = require('react-immutable-render-mixin').immutableRenderDecorator;

var shallowEqualImmutable = require('react-immutable-render-mixin').shallowEqualImmutable;

var shouldComponentUpdate = require('react-immutable-render-mixin').shouldComponentUpdate;

Full Example:

var immutableRenderMixin = require('react-immutable-render-mixin').default;

React.createClass({
  mixins: [immutableRenderMixin],

  render: function() {
    return <div className={this.props.className}>foo</div>;
  }
});

More Repositories

1

react-validation-mixin

Simple validation mixin (HoC) for React.
JavaScript
284
star
2

refactoring-codemods

Refactoring support for JavaScript via jscodeshift codemods
JavaScript
79
star
3

react-display-name

utility to return a react components display name
JavaScript
59
star
4

atom-javascript-refactor

atom plugin that provides refactoring support for JavaScript
JavaScript
32
star
5

redux-pouchdb-store-enhancer

Redux PouchDB Enhancer to store actions locally, sync with remote CouchDB, and time travel by applying remote actions locally and then compute distributed nextState.
JavaScript
22
star
6

joi-validation-strategy

Joi validator for react-validation-mixin
JavaScript
9
star
7

redux-online-store-enhancer

Automatically detect if you are online or offline.
JavaScript
8
star
8

redux-peerjs-store-enhancer

Use PeerJS to easily distribute Redux actions to remote peers.
JavaScript
7
star
9

react-examples

React Examples
JavaScript
6
star
10

test-timebomb

πŸ’₯ auto expire features in your code
JavaScript
5
star
11

dataflow-through-react

Gitbook for 2015 Connect js talk on dataflow through React
4
star
12

data-structures

CS Basics + Js Basics Conference Slides
JavaScript
3
star
13

docs-react-validation-mixin

gitbook documentation for react-validation-mixin
2
star
14

http-benchmark

Scriptable Http Benchmarking util for node
CoffeeScript
2
star
15

jurassix.github.io

1
star
16

my-create-react-app

Default application, built from Create React App, with Flow and redux wired up.
JavaScript
1
star
17

redux-action-enhancer-middleware

Middleware that provides an enhancing function to dispatched actions, with optional filtering to target only certain actions.
JavaScript
1
star