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

Using 'without' method to prevent circular references #125

Closed ghost closed 8 years ago

ghost commented 8 years ago

Withoutcan be very usefull to prevent circular references in situations like that.

let objA = {a : 1},
    objB = {objA, b : 2};
objA.objB = objB;
let ImmutableA = Immutable(objA).without("objB");
// ImmutableError: Attempt to construct Immutable from a deeply nested ...

Can you make option or function without?

let ImmutableA = Immutable(objA, {without : ["objB"]});
// no error
rtfeldman commented 8 years ago

Why not just transform the argument before calling Immutable on it?

ghost commented 8 years ago

Argument object may all propetiies to work properly. Second way is to clone it for N depth, delete props and send cloned to Immutable. But its not equal if object has depth L>N.

rtfeldman commented 8 years ago

This use case seems too narrow to justify the added complexity, sorry!