-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How should the parent pass in new layout(s)? #156
Comments
Worse still, if you reset a layout by calling I don't want to move the check back to |
Would this be solved if every passed prop and every state would be immutable? I use RGL on a Flux/Redux Immutable js stack. Maybe in long term it would be better to switch to Redux as well. |
+1 for redux |
Well, we definitely wouldn't use it in a library - not sure what you're suggesting. And Immutable is very slow and a large dependency. We could clone the layout items when they come in. Since the shapes are regular we could do a very fast custom clone. That should help and we could start implementing a better SCU. |
@STRML redux without any explanation was indeed misleading. I may miss the point and this is total nonsense: imho We could create a simple object which stores the layout and has a function to every action like 'item drag start', 'item dragged', 'item drag stop' which each call a list of reducer functions (move, compact etc.) to mutate the layout. With this solution reducers can also be overridden or enhanced with custom user defined functions. This would also move all layout logic from RGL to the store which leads to a clean and solid architecture. Testing and middleware functions should profit as well. Moreover the store could be passed as a simple provider HOC where layouts are passed down as props and action functions are made available as context. The current RGL and Responsive RGL components would then only deal with view logic and action calls. On the downside: Concerning immutable: imho the first reason for immutable is cloning, the second is comparing. |
I'll have to bench it, but my intuition is that given a fast cloning function that assumes an object shape, we'll be able to clone layouts faster than we would with Immutable, or at least fast enough to make the large dependency not worthwhile. If the cloning can be properly optimized, it can be very, very fast. Normal _.clone()-style functions are not because they have to do property lookups, which causes the underlying object to become a slow object / hash, which is why, confusingly, even JSON.parse(JSON.stringify(object)) can be faster. In a sense, I think the proper API may be:
This makes it clear that this property, if changed, will be ignored. And when you need to force-push a new layout, you do I don't see a better way to do such an imperative action with React's declarative nature. I agree re: reducer functions, which is essentially what we already have in I'm not sure we need to basically re-implement Redux here otherwise. That will make the API of this component significantly different than most React components, and I don't see a good reason for that. There's a lot of low-hanging fruit here in terms of |
In my own project I needed to know if stateless components with explicit Principles:
shouldComponentUpdate(nextProps) {
if (this.props.placeholder !== nextProps.placeholder) return true;
if (!this.props.children.length !== nextProps.children.length) return true;
if (!this.props.layout !== nextProps.layout) return true;
if (!this.props.containerWidth !== nextProps.containerWidth) return true;
return false;
} Therefore changed layouts need to be cloned in order to force an update. shouldComponentUpdate(nextProps, nextState) {
return (!shallowEqual(this.props, nextProps));
} Simplified design:
Results: I still do not know to make simple synthetic tests in this case. I made my test on OSX/lastest stable Chrome with 0-showcase example and optimized build configs (taken relevant parts from webpack.config.js to webpack-dev-server.config.js) I made several runs, here are two graphs to each branch: https://github.com/menelike/react-grid-layout/commits/performance Scripting performance is reduced, painting increased, overall reduced. But I'm not an expert on this, further tests are required, results could be absolutely misleading. |
i created something like prototype for redux wrapper for grid: i'm still new at react/redux so sure it's not a best solution. It's not a real package yet, still working on it - just wanted to put it online, because i already have some question: looks like update layout is not enough, because Grid does not update state :( Drag/Resize works fine because i update layout with 'layout' that came from callback. But when i remove item, it does not work - redux shows that state was updates, but grid is not updated visually (i mean item was removed, but compact was not happen) :( Any ideas? |
@plandem without investigating your code. Set all |
i will try, i hoped that common 'connect' from redux will be enough, but if i have to add custom logic to 'shouldComponentUpdate' then looks like i will have to create HOC manually :( i talked about this HOC that came from connect: |
'shouldComponentUpdate' does not help |
@plandem my code mentioned above could work better with higher redux stores. But keep in mind that
|
at my reducer i do:
where:
and compactor is:
so as you see - after 'remove' action reducer update layout totally. And it's updated at store if i debug, but at grid - nope :(
although grid is using layout prop, so it must actually get updates :( |
actually i would like to have stateless Grid and HOC for layout changes. In that case custom logic can be attached more easily, for example all these -'drag/resize' events with redux must be used at reducers. But in current scenario, looks like it's not possible :( So we can't separate 'view' and logic for view :( |
@plandem I may miss the point, but my code is made for exactly that use case. If you store the layout which has been sent to your higher function trough I haven't tested this with outer Redux/Immutable stack where you only store immutable objects and therefore converting layout to immutable would cause an update, even if they layout hasn't changed at all. This is because we would need deep comparisons here. |
yeah, your code looks like right way. but it's fork in that case :( i was talking about structure of that library :) for optimisation probably this can help: |
that's what I tried first, but I then realized the component needs to be stateless and the impact on existing code can't be done with just a HOC (we do not need a HOC anway, gonna change that soon). I actually need to do further tests, I'm not sure, but this code could actually replace existing code without an impact on the API imho the current master solves the same issue, just not in the stateless way. I still need to understand #164 for a final conclusion. concerning reselect, that's a very good choice in an application but not in a library. @STRML was absolutely right when he said redux/immutable should not be used in a library. Therefore reselect should provide your application component and not in RGL. There you can also use your own |
I just ran into this today before heading home. Hope to report back with findings and ideas. Love this package. |
when minimizing the screen the grids are not minimizing can anyone please solve it |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 7 days |
Related to #98
This is an open issue for comment.
Currently, the following methods are used to determine whether or not to reload the layout:
RGL:
!_.isEqual(this.props.layout, nextProps.layout)
ResponsiveRGL:
``!_.isEqual(this.props.layouts, nextProps.layouts)`
This doesn't adequately cover some use issues, like:
This is actually very similar to the problem that caused me to rewrite
<Draggable>
in the first place. It's difficult, in React, to enforce a state reset on children at some times while allowing them to manage their own state at other times.Should users just simply grab a ref and
setState()
themselves? I don't know if I see a better option.The text was updated successfully, but these errors were encountered: