support for iterable structures within state#79
Conversation
|
Good stuff, thank you! Anybody else wants to test drive this? |
|
I think i do eventually at least |
|
With a couple of changes, this will work for |
There was a problem hiding this comment.
Change to the following
if (typeof data.count === 'function') {
count = data.count();
} else if (typeof data.size !== 'undefined') {
count = data.size;
} else {
count = data.length;
}To handle the length of a Map()
There was a problem hiding this comment.
Yeah, I agree. I had the size there before, but then I've noticed that MoriJS has only count method.
I am thinking if it wouldn't be better to use iterator even here to count entries. That would be unified way. I would like to avoid adding another property/method in a future if some other data structure implementing iterator would use different name for this. Some library could even have a like size being method or count being property.
There was a problem hiding this comment.
Alright, I've change it. It uses the size property as it's the most common (only mori doesn't have it), otherwise it counts entries through the iterator. I am not using length because it's deprecated in Immutable anyway and others doesn't have it at all.
There was a problem hiding this comment.
Another small change to use Number.isSafeInteger for the size property. It should be safer way in case some library has size as a function.
|
Out in 1.1.0, let me know how it goes! |
Alright, I finally needed this so badly that I had to do it :) I haven't tested all available structures, but here is view of my Immutable.List of Immutable.Record instances within state.
Fixes #51, #66, #70