Comments (7)
It may be argued that isIteratorResult
should return return has(value, 'value') || has(value, 'done')
, however the bug is triggered by has
implementation, which returns false for value: undefined
, which is definitely incorrect.
The proper syntax goes like this: value
must be always present, and done
is optional. However, all JavaScript implementations feature both at all times, i.e. the last element is always {value: undefined, done: true}
.
But let's look at how IteratorResult
is defined within ES2015 that we are using:
interface IteratorYieldResult<TYield> {
done?: false;
value: TYield;
}
interface IteratorReturnResult<TReturn> {
done: true;
value: TReturn;
}
type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
So we can see that done
is optional while inside generators, which is odd, but ok. That's why I think that fixing has
implementation is more appropriate.
@RebeccaStevens What do you think? If you agree, please make the change 😉
from iter-ops.
Verified fix in 2.8.0. Thanks!
from iter-ops.
@RebeccaStevens b.t.w., you have this comment inside has
- // Cannot use in operator as it doesn't work for strings.
Perhaps hasOwnProperty is usable for this? ;)
The difference from in
is as follows...
Unlike the
hasOwnProperty()
method, thein
operator will return true for both direct and inherited properties that exist in the object or its prototype chain.
But our {value, done}
is always a simple object, it is never a class ;) So the question is - are we ever use it for classes? Anyway, I'm leaving it up to you.
from iter-ops.
Object.prototype.hasOwnProperty
(or Object.hasOwn
) is usually my go to for this, but it doesn't work in this case.
In general, we need to know if the object has the key, regardless of if it's direct or inherited. Not for the case of isIteratorResult
, but for the other functions such as isSyncIterable
and isPromiseLike
.
Additionally, that function doesn't work for symbols (Object.getOwnPropertySymbols
would need to be used for symbols, but again, that's for direct symbols).
I deicide it is best to go back to using the in
operator. If we convert the object to an Object
first, then it should work as desired.
from iter-ops.
v2.8.0-beta.2 now contains the fix.
I'm gonna play a little with the new concurrencyFork operator within iter-ops-extras, to make sure it is as every bit as good as I was expecting, and then will make a proper 2.8.0 release 😉
@RebeccaStevens Never got your view on the new concurrencyFork
addition (in the discussions). I think it is a game changer. What do you reckon?
from iter-ops.
It looks good. I'll have a more in-depth look at it a bit later.
from iter-ops.
The fix for this was released in v2.8.0.
@RebeccaStevens I tested it out (concurrencyFork
) thoroughly, and it was good, so I have released it ;)
from iter-ops.
Related Issues (20)
- Add support for infinite timeouts HOT 1
- Extend "last" operator with iteration state HOT 17
- "reduce" callback gets incorrect index HOT 1
- pipeSync should throw an error on any asynchronous input
- pipeAsync should be able to accept Promise as input HOT 4
- Add async callback support to operator "reduce" HOT 5
- Initial value delayed in waitRace operator HOT 17
- Operator waitRace should deactivate when cacheSize < 2 HOT 1
- start vs stop logic inconsistency HOT 11
- Operators "wait" and "waitRace" should simply forward in sync mode HOT 2
- Post-merge issues of decoupling the interface HOT 31
- Operator concurrencyFork should handle pipeline-construction errors HOT 1
- Review toIterable logic HOT 3
- Operator timeout should forward callback errors HOT 1
- Operator timeout should account for the first value. HOT 1
- Benchmark Readme statement about RXJS subscription is incorrect. HOT 3
- takeUntil takes iterates to one more elements HOT 1
- Further iterable extension with method `Add` HOT 1
- `flat` is not consistent with `Array.flat` HOT 2
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 iter-ops.