GithubHelp home page GithubHelp logo

Comments (9)

acdlite avatar acdlite commented on July 20, 2024

mapPropsOnUpdate() is just a shortcut for compose(shouldUpdate(...), mapProps(...)). If you want more control over when to update, use that.

from recompose.

istarkov avatar istarkov commented on July 20, 2024

It's not compose of shouldUpdate and mapProps
component may update and not recalculate some internal values.

Your code for mapPropsOnUpdate does not contain any shouldComponentUpdate calls.

And there is no method like
mapPropsOnUpdate(props => myCompareFn, props => newProps)

from recompose.

acdlite avatar acdlite commented on July 20, 2024

Ah you're right, clearly I don't know my own library well enough :)

Let me think about this one for a bit.

from recompose.

acdlite avatar acdlite commented on July 20, 2024

I know the implementation is slightly different, but is there any reason why compose(shouldUpdate(...), mapProps(...)) wouldn't achieve the desired effect?

from recompose.

istarkov avatar istarkov commented on July 20, 2024

I need to redraw but not to call again some intensive calculate function.
And in redraw i need result of that function.
And if some props changed, i need to run calculate function again after some additional checks.

Animation - in my current task.
I have map with svg tiles over it.
Instead of full svg path points position recalculation i can use css transforms until some props changes.

For example i scale on zoom oversimplified map tiles until tiles for new zoom level arrived.
Tiles preparation for swg drawing is really intensive task.
Also I can't call recalculate until google map stop animation (otherwise it breaks animation)

So i check shallow equality on some props inside componentWillReceiveProps,
and if it false I make additional checks - could i reuse previous calculation partially or need to make full recalc again.

But I need to react on other props changes.

It's something like reduce operation - take some new data, take previous result and create something new if needed.

from recompose.

acdlite avatar acdlite commented on July 20, 2024

I have a mostly-finished withReducer() helper that I'll push soon. I think it may address your issue.

from recompose.

istarkov avatar istarkov commented on July 20, 2024

Thank you!!!
recompose is really fun library.

from recompose.

acdlite avatar acdlite commented on July 20, 2024

Closed by #10

from recompose.

istarkov avatar istarkov commented on July 20, 2024

In combination with doOnReceiveProps as like as I need
withReducer will cause Warning: setState(...): Cannot update during an existing state transition (such as within render).

Because of call to some parent setState inside child constructor.

Calls actions inside componentWillReceiveProps are OK but gives additional render.

IMHO this withReducer is good for most situations except mine.

All I need is this.

const createReduce = (reducer, BaseComponent) => (
  class Reduce extends React.Component {
    static displayName = wrapDisplayName(BaseComponent, 'Reduce');

    constructor(props, context) {
      super(props, context);
      this.memo_ = reducer(undefined, props);
    }

    componentWillReceiveProps(nextProps) {
      this.memo_ = reducer(this.memo_, nextProps);
    }

    render() {
      return <BaseComponent {...this.props} {...this.memo_} />;
    }
  }
);

from recompose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.