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 seamless-immutable in a jsbin #39

Closed dagda1 closed 9 years ago

dagda1 commented 9 years ago

I'm trying to use seamless-immutable in this jsbin but whenever this line is ran:

var array = Immutable(["foo", "foo2", "bar", "bar2", "baz", "baz2"]);

I get this error:

Uncaught TypeError: Cannot redefine property: [object Object]

And this stack trace:

addPropertyTo   @   seamless-immutable.js:5
makeMethodReturnImmutable   @   seamless-immutable.js:84
makeImmutableArray  @   seamless-immutable.js:94
Immutable   @   seamless-immutable.js:328
(anonymous function)    @   nesomi.js:36
applyStr    @   ember.debug.js:18054
sendEvent   @   ember.debug.js:12373
exports.default.mixin.Mixin.create.trigger  @   ember.debug.js:29705
superFunction   @   ember.debug.js:13704
EmberObject.default.extend.trigger  @   ember.debug.js:40271
superWrapper    @   ember.debug.js:17586
Renderer.default.didInsertElement   @   ember.debug.js:38923
Renderer_renderTree @   ember.debug.js:8480
scheduledRenderTree @   ember.debug.js:8506
Queue.invoke    @   ember.debug.js:871
Queue.flush @   ember.debug.js:936
DeferredActionQueues.flush  @   ember.debug.js:741
Backburner.end  @   ember.debug.js:166
Backburner.run  @   ember.debug.js:221
executeTimers   @   ember.debug.js:603
(anonymous function)    @   ember.debug.js:592
rtfeldman commented 9 years ago

Hm...seems to work fine in a Node REPL:

> var Immutable = require("seamless-immutable")
undefined
> var array = Immutable(["foo", "foo2", "bar", "bar2", "baz", "baz2"]);
undefined
> array
[ 'foo', 'foo2', 'bar', 'bar2', 'baz', 'baz2' ]

My first guess would be that Ember modifies Array.prototype in some way that is incompatible with seamless-immutable...do you know if that's something Ember does?

dagda1 commented 9 years ago

Yes, you are right, ember does modify the prototype. You can turn that off though.

Thanks

dagda1 commented 9 years ago

I've stopped ember extending the prototypes and I get a new error:

Uncaught ReferenceError: process is not defined

Which references this code:

    if (process.env.NODE_ENV === "development") {
      // Make all mutating methods throw exceptions.
      for (var index in bannedMethods) {
        banProperty(obj, bannedMethods[index]);
      }

Is this library node only?

Here is the updated jsbin

rtfeldman commented 9 years ago

@dagda1 This is happening because you're importing the seamless-immutable source, not the compiled version (which has process stripped out). Try importing one of these instead:

seamless-immutable development mode (with freezing and helpful exception messages) seamless-immutable production mode (minified, and runs faster, but doesn't freeze objects or offer helpful exception messages)

rtfeldman commented 9 years ago

@dagda1 Did this fix the issue you were having?

dagda1 commented 9 years ago

Sorry, yes, thanks