React-sortable-hoc: Import arrayMove from 'array-move';Module problems

Created on 29 Aug 2019  ·  11Comments  ·  Source: clauderic/react-sortable-hoc

The import arrayMove from 'array - move;Where does this "array-move" come from?I have been writing for a long time without finding this module

All 11 comments

It comes from react-sortable-hoc. You can import like this
import { arrayMove } from 'react-sortable-hoc';

Thank you,I've made it.

It will eventually be removed though and it's preferable to use the array-move package.

@ABouchard55 that's how we end up with 1 billion modules in the javascript ecosystem.

@ABouchard55 that's how we end up with 1 billion modules in the javascript ecosystem.

Thanks for the downvote, but I didn't say this out of my ass, it's literally written in the code that he will remove it: https://github.com/clauderic/react-sortable-hoc/blob/1c69772bd4df0d40828531288faad95888be4b5a/src/utils.js#L5

that's how we end up with 1 billion modules in the javascript ecosystem.

More packages handling specific concerns means less duplication across modules and therefore smaller bundle sizes served to your users.

The rationale behind this change is that re-ordering items in an array is not a concern that specifically needs to be handled by the library. It is a concern for the consumer, and could be handled in a number of different ways (for instance, the consumer could choose to mutate the array instead of creating a new one for performance reasons, or might already be using a library/util elsewhere in their application to move items in an array).

In either case, it's a simple find and replace to import arrayMove from 'array-move'; instead of from react-sortable-hoc, and we've been warning in development for quite some time now that this change would be coming in the next major version. This is simply the recommended package in documentation, feel free to use a different library or write your own method to sort the array.

More packages handling specific concerns means less duplication across modules and therefore smaller bundle sizes served to your users.

I only needed arrayMove for this library(didn't really need it at all but it was in the example so i followed it), so in my case its actually a direct increase of module size. moving items in arrays is incredibly trivial anyway, most developers would have rolled an implementation for it atleast once.

@ABouchard55 that's how we end up with 1 billion modules in the javascript ecosystem.

Thanks for the downvote, but I didn't say this out of my ass, it's literally written in the code that he will remove it:

https://github.com/clauderic/react-sortable-hoc/blob/1c69772bd4df0d40828531288faad95888be4b5a/src/utils.js#L5

My apologies, i didn't mean to offend you. I thought you were a package maintainer.

I only needed arrayMove for this library(didn't really need it at all but it was in the example so i followed it), so in my case its actually a direct increase of module size. moving items in arrays is incredibly trivial anyway, most developers would have rolled an implementation for it at least once.

This statement doesn't hold water.

If you use a modern bundler for your application such as Webpack, the current arrayMove helper that is included in react-sortable-hoc will be treated as dead code if you do not use it (for example, if you use array-move) and will be eliminated from the final bundle.

If not, you're also free to continue to use the arrayMove helper that is bundled in the library today, and migrate to a different solution when it is removed in the next major version that is released.

As mentioned above, the array-move package is _not_ required, feel free to use something else or roll up your own solution, it is simply the recommended approach in documentation.

This statement doesn't hold water.

You really are trying to bend my words there bud.

I said:

in my case its actually a direct increase of module size.

which is true if:

  • i use arrayMove imported from array-move instead of imported from react-sortable-hoc. this is because each module has its own module overhead.

My purpose is not to bend your words. I'm writing this for posterity so that other users of the library that stumble on this issue are not misinformed.

As I mentioned above, assuming you're using a modern bundler to package your application, the arrayMove function that is included in react-sortable-hoc will be treated as dead code and be eliminated from your final bundle if you do not use it.

In the event that you are not using a modern bundler that is capable of tree shaking, you're free to continue using the arrayMove helper that is included in react-sortable-hoc today. You are not obligated to use the array-move package. Just know that this util will be removed from the next major version.

Was this page helpful?
0 / 5 - 0 ratings