ccorcos / reactive-magic

Magical reactivity at your fingertips that helps you build complex applications quickly
40 stars 0 forks source link

Fixing unnecessary view rendering #1

Closed ismail-codar closed 7 years ago

ismail-codar commented 7 years ago

Fixing one time data change affecting two times view rendering.

ccorcos commented 7 years ago

My intention here is that if you use any reactive data within willMount, that function will get re-run anytime some data changes. Although, I haven't used that functionality much.

Ok, now I see what you're talking about. React is not actually rendering twice (React has its own internal queuing system when you use setState), but we're still calling you view function twice.

This should fix the problem you're having.

   // leverage React's render loop
   state = { updates: 0 };
   _update = () => {
     this._needsUpdate = true
     this.setState({ updates: this.state.updates + 1 });
   };
ismail-codar commented 7 years ago

Yes if the data is the same, calling view function will not make the render more. But the virtual dom diffing is invoked unnecessarily so loss performance occurs. If enter the queuing system before the virtual dom diffing it is nice.

I do not fully understand your need to use reactive data. But if done consciously, there is no problem. Nevertheless, I feel that there must be another solution to this point. Maybe not this PR.

ccorcos commented 7 years ago

I think the change I made above should work. I dont have time to do it right now, but I'll check it out later