-
Notifications
You must be signed in to change notification settings - Fork 21
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
Add support for Immutable.js #23
Comments
Ok what kind of structure do you have ? I've never worked with immutable.js but we are 100% read only so I'm confident we can. |
I'm thinking of providing a callback that could be used in a map like function. var cb = fz.callBackFor(query,option) Altougth sorted probably need mutability |
@jeancroy we have a list of maps (array of plain objects in pure JS). Immutable.js has sort method so that's not a problem. The only difference between array of plain objects and Immutable structures for this library are getters. For plain objects you use the dot sign Maybe we could pass some flag so you would know the structure is Immutable. |
This is how I iterate over the list and extract the key to be ranked I could provide a "getterFunc" in the optionHash that input the element and output the value to be scored. Would that make sens, flexibility and performance wise ? |
I will try to hack it and let you know if that's enough or something else needs to be changed. |
Ok so here are results: Changes in file fuzzaldrin.cofee: Before:
After:
Changes in file filter.coffee are here https://www.diffchecker.com/899ruzir. So now I'm not sure if we should try to put support for immutable.js into your lib or I should just fork it and call it something like immutable-fuzzaldrin. What do you think @jeancroy? |
I'm looking at the Immutable documentation
With this in mind i'd probably adapt the following line to use withMutations so you don't end up creating 300 different immutable list before sorting.
Pushing on the idea that you want to avoid .toJS for performance reason I think we can do the following:
Basically let's assume you have 5000 items and at the end want to take the top 10. Moreover this would increase the shared codepath between immutable / classic JS, so the immutable implementation could fit inside two function input transform (extract) and output transform ( array -> immutable collection) The input /output transform could be re-used to support other data structures, maybe other implementation of immutable, or even complex / computed key object.x.y.z What do you think ? |
Basically what I'm trying to say is that by nature scoredCandidates is an object that will mutate once per item then .. as soon as it stop mutating... it get discarded with sort pluck and take. so it's very anti immutable by nature, and not moving this one, I think it's possible to have easier cohabitation between normal, immutable and others. |
@jeancroy Sounds like a better solution. I'm up for that 👍. |
@jeancroy Any idea when this could be implemented? |
Hi @petrbrzek just a head up. There's now a es6 branch on which I redesigned the filtering. There'll be support for cancelable async as well as iterating over array, anything that support es6 iterator and anything with .forEach method. They 'key' options also support functions, so one can write I still have to write test & benchmark, but with those changes the library will officially support Immutable.js Also, Merry Christmas ! |
It would be really nice to seamlessly use this library with Immutable.js structures. Now we must call
.toJS()
and that could be a bottleneck.The text was updated successfully, but these errors were encountered: