Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ImmutableObject.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

var createObject = require("./lib/createObject");

function ImmutableObject(props) {
if (typeof props === "undefined") {
return empty;
Expand All @@ -13,7 +15,7 @@ function ImmutableObject(props) {
return empty.set(props);
}

var empty = Object.freeze(Object.create(ImmutableObject.prototype));
var empty = Object.freeze(createObject(ImmutableObject.prototype));

ImmutableObject.prototype.set = function(props) {
if (!props) {
Expand Down Expand Up @@ -49,7 +51,7 @@ ImmutableObject.prototype.set = function(props) {
value = require("./factory")(value);
propertyDefs[key] = { value: value, enumerable: true };
});
var newObj = Object.create(this, propertyDefs);
var newObj = createObject(this, propertyDefs);
Object.freeze(newObj);
return newObj;
};
Expand Down Expand Up @@ -124,4 +126,3 @@ ImmutableObject.keys = function(obj) {
};

module.exports = ImmutableObject;

6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ task = task.done();
console.log(task.toString());
```

## Running Benchmark Script

Run `npm run bench` to run the benchmark script using node.

Run `PORT=8080 npm run bench-server` to start an HTTP server on port
8080 that will serve the benchmark script to browsers.
14 changes: 14 additions & 0 deletions bench/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var immutable = require("../");
var OBJ = require("./obj.json");

console.time("create");
var o = immutable(OBJ);
console.timeEnd("create");

console.time("overwrite");
o.set(OBJ);
console.timeEnd("overwrite");

console.time("set");
o.set({ test: OBJ });
console.timeEnd("set");
Loading