rtfeldman / seamless-immutable

Immutable data structures for JavaScript which are backwards-compatible with normal JS Arrays and Objects.
BSD 3-Clause "New" or "Revised" License
5.37k stars 195 forks source link

Doesn't play well with Symbols (generators?) #107

Open sandro-pasquali opened 8 years ago

sandro-pasquali commented 8 years ago

Great library. I have a pretty esoteric case, but the failure seems to be real.

This code:

let context = {
    * [Symbol.iterator]() {
        yield Promise.resolve(1);
        yield Promise.resolve(2);
    }
};

for (let P of context) {
    console.log(P.value());
}

// 1
// 2

Fails if wrapped by Immutable:

let context = Immutable({
    * [Symbol.iterator]() {
        yield Promise.resolve(1);
        yield Promise.resolve(2);
    }
});

...

for (let P of context) {
              ^
TypeError: undefined is not a function

I'm not sure if it is the generator or the symbol usage (or computed property keys or the compact object method signature) that's causing the problem.

Running on Node (5.x), with --harmony flag. Also, bluebird is the Promise implementation.

tusharmath commented 8 years ago

@sandro-pasquali How is this supposed to behave like an immutable? The very fact that a generator generates values means that its not static and hence a mutable.

rtfeldman commented 8 years ago

Hm...I honestly have not looked into these things enough to know what the problem could be.