Comments (21)
Naw (ok, ya I know it's weird I answered my own question :P)
It's totally edge and devs needing it can opt for something like _.shuffle(_.values(obj))
.
Lo-Dash optimizes for the common case.
from lodash.
Shuffle was added to Underscore with the intent of being for arrays and only ran into objects because of its overuse/dependency on _.each
.
See
jashkenas/underscore#71
and
jashkenas/underscore@f4cba51
from lodash.
Perf info:
from lodash.
I'm REALLY not a big fan of doing "array" things on objects. Like the signature added to jQuery.map
in 1.6:
http://api.jquery.com/jQuery.map/
from lodash.
I'm REALLY not a big fan of doing "array" things on objects. Like the signature added to jQuery.map in 1.6:
Ya, a lot of the time it just doesn't fit. I've moved methods like _.min
, _.max
, _.shuffle
, _.sortBy
and _.groupBy
from "Collections" (objects and arrays) to "Arrays" to simplify each and optimize them for their common and tested/documented usage.
from lodash.
IMHO, It depends on the philosophy behind Lo-Dash.
Since Lo-Dash supports custom build, it would be nice to have an equivalent drop-in replacement version and a lite or Lo-Dash-way version.
However this means Lo-Dash should maintain two versions of doc and src.
from lodash.
Since Lodash supports custom build, it would be nice to have an equivalent drop-in replacement version and a lite version.
As API's shift I have planned on making a lodash.underscore.js
build.
from lodash.
@jdalton So what's the core philosophy on Lo-Dash? Making it different from underscore.
from lodash.
@floydsoft
So what's the core philosophy on Lo-Dash? Making it different from Underscore.
Jeremy wrote:
The original idea with Underscore was to take the common set of useful data-manipulation primitives that you often need when working on a large JS application, and implement them in the fastest, smallest, and least invasive way possible -- so that if you need to just throw in Underscore into an existing application or web page to use a helper or two, it's never a problem to do so.
Unfortunately, Underscore has core design flaws that prevent it from being a simple drop-in utility and has since taken the stance to no longer concern itself with cross-browser consistency and close issues or revert patches instead of fixing real bugs.
As browsers progress the need for a lot of this API sugar will disappear because developers in ES5 compatible environments will use more native methods. So Underscore's BIG draw should be that it provides these features for older browsers in a consistent and cross-browser way. Its punt on consistency defeats a big reason to use it.
I started Lo-Dash with a focus on performance, consistency (in API and usage), and customizability. I wanted to show that it's possible to fix real issues like object iteration bugs in IE, Firefox, Opera, and Safari without sacrificing performance or adding mass bloat. I've taken it up a notch by providing custom builds, better documentation, and more debug helpers too.
from lodash.
I started Lo-Dash with a focus on performance, consistency (in API and usage) and customizability.
Having consistency in mind, implicitly transmuting object to array wouldn't be a good design.
Therefore, moving shuffle's clients from Collections to Arrays is a proper change.
from lodash.
As of Lo-Dash v0.8.2 _.groupBy
, _.max
, _.min
, _.shuffle
, and _.sortBy
work with objects.
from lodash.
@jdalton interesting, why make the change?
from lodash.
@floydsoft I was able to find a way to keep the more common array usage fast while supporting objects for Underscore compat. The change was made so that the lodash underscore
build removes all edge case compat issues.
from lodash.
Could you share the tip you found ?
from lodash.
@floydsoft Here is an example of the fast path for _.max.
from lodash.
@jdalton by length !== +length
? cool!
but why don't use length === undefined
from lodash.
@floydsoft To be consistent with how collections
are detected.
from lodash.
so why don't detect collections with length === undefined
?
from lodash.
@floydsoft because making the check a bit more tight allows non numeric lengths to be avoided. A collection must a length that is a number primitive.
from lodash.
@jdalton ok, I've understood, thx!
from lodash.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from lodash.
Related Issues (20)
- orderBy orders field boolean dosent work HOT 1
- Please republish lodash.forin HOT 4
- Wrong version in lodash.pick vulnerability report CVE-2020-8203 HOT 8
- `lodash.merge` drops keys that are symbols
- Type of parameter object is string in function baseGet(object, path)
- cloneDeep not cloning nested Map
- Method `sumBy` returns string HOT 2
- EOL
- _.isEqual() returns false when array elements order is changed HOT 6
- Merge mutates source object if nested property is a class instance
- Future compatibility with Node.js/npm HOT 1
- Allow Default Value for toNumber("problem", 0) HOT 8
- isBuffer from lodash-es doesn't work HOT 1
- curryRight is broken in list.map context HOT 1
- Avoiding Lodash version disclosure HOT 1
- multiple vulnerabilities that exist in lodash.findlast HOT 4
- Attempt structuredClone in cloneDeep before doing manual clone HOT 4
- _.trimStart not work with "/" char
- No
- _.kebabCase and _.camelCase treat some digits as delimiters but not others HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lodash.