immutable
Advanced tools
Comparing version 3.6.1 to 3.6.2
@@ -31,4 +31,4 @@ /** | ||
keyPath = []; | ||
} else if (!Array.isArray(keyPath)) { | ||
keyPath = [keyPath]; | ||
} else { | ||
keyPath = valToKeyPath(keyPath); | ||
} | ||
@@ -78,11 +78,9 @@ return makeCursor(rootData, keyPath, onChange); | ||
KeyedCursorPrototype.getIn = | ||
IndexedCursorPrototype.getIn = function(key, notSetValue) { | ||
if (!Array.isArray(key)) { | ||
key = Immutable.Iterable(key).toArray(); | ||
} | ||
if (key.length === 0) { | ||
IndexedCursorPrototype.getIn = function(keyPath, notSetValue) { | ||
keyPath = listToKeyPath(keyPath); | ||
if (keyPath.length === 0) { | ||
return this; | ||
} | ||
var value = this._rootData.getIn(newKeyPath(this._keyPath, key), NOT_SET); | ||
return value === NOT_SET ? notSetValue : wrappedValue(this, key, value); | ||
var value = this._rootData.getIn(newKeyPath(this._keyPath, keyPath), NOT_SET); | ||
return value === NOT_SET ? notSetValue : wrappedValue(this, keyPath, value); | ||
} | ||
@@ -92,3 +90,3 @@ | ||
KeyedCursorPrototype.set = function(key, value) { | ||
return updateCursor(this, function (m) { return m.set(key, value); }, key); | ||
return updateCursor(this, function (m) { return m.set(key, value); }, [key]); | ||
} | ||
@@ -103,3 +101,3 @@ | ||
IndexedCursorPrototype['delete'] = function(key) { | ||
return updateCursor(this, function (m) { return m.remove(key); }, key); | ||
return updateCursor(this, function (m) { return m.remove(key); }, [key]); | ||
} | ||
@@ -177,5 +175,5 @@ | ||
KeyedCursorPrototype.cursor = | ||
IndexedCursorPrototype.cursor = function(subKey) { | ||
return Array.isArray(subKey) && subKey.length === 0 ? | ||
this : subCursor(this, subKey); | ||
IndexedCursorPrototype.cursor = function(subKeyPath) { | ||
subKeyPath = valToKeyPath(subKeyPath); | ||
return subKeyPath.length === 0 ? this : subCursor(this, subKeyPath); | ||
} | ||
@@ -191,3 +189,3 @@ | ||
return deref && deref.__iterate ? deref.__iterate( | ||
function (v, k) { return fn(wrappedValue(cursor, k, v), k, cursor); }, | ||
function (v, k) { return fn(wrappedValue(cursor, [k], v), k, cursor); }, | ||
reverse | ||
@@ -216,3 +214,3 @@ ) : 0; | ||
var k = entry[0]; | ||
var v = wrappedValue(cursor, k, entry[1]); | ||
var v = wrappedValue(cursor, [k], entry[1]); | ||
return { | ||
@@ -240,10 +238,10 @@ value: type === Iterator.KEYS ? k : type === Iterator.VALUES ? v : [k, v], | ||
function wrappedValue(cursor, key, value) { | ||
return Iterable.isIterable(value) ? subCursor(cursor, key, value) : value; | ||
function wrappedValue(cursor, keyPath, value) { | ||
return Iterable.isIterable(value) ? subCursor(cursor, keyPath, value) : value; | ||
} | ||
function subCursor(cursor, key, value) { | ||
function subCursor(cursor, keyPath, value) { | ||
return makeCursor( | ||
cursor._rootData, | ||
newKeyPath(cursor._keyPath, key), | ||
newKeyPath(cursor._keyPath, keyPath), | ||
cursor._onChange, | ||
@@ -254,6 +252,7 @@ value | ||
function updateCursor(cursor, changeFn, changeKey) { | ||
function updateCursor(cursor, changeFn, changeKeyPath) { | ||
var deepChange = arguments.length > 2; | ||
var newRootData = cursor._rootData.updateIn( | ||
cursor._keyPath, | ||
changeKey ? Map() : undefined, | ||
deepChange ? Map() : undefined, | ||
changeFn | ||
@@ -266,3 +265,3 @@ ); | ||
cursor._rootData, | ||
arguments.length > 2 ? newKeyPath(keyPath, changeKey) : keyPath | ||
deepChange ? newKeyPath(keyPath, changeKeyPath) : keyPath | ||
); | ||
@@ -276,5 +275,15 @@ if (result !== undefined) { | ||
function newKeyPath(head, tail) { | ||
return Seq(head).concat(tail).toArray(); | ||
return head.concat(listToKeyPath(tail)); | ||
} | ||
function listToKeyPath(list) { | ||
return Array.isArray(list) ? list : Immutable.Iterable(list).toArray(); | ||
} | ||
function valToKeyPath(val) { | ||
return Array.isArray(val) ? val : | ||
Iterable.isIterable(val) ? val.toArray() : | ||
[val]; | ||
} | ||
exports.from = cursorFrom; |
{ | ||
"name": "immutable", | ||
"version": "3.6.1", | ||
"version": "3.6.2", | ||
"description": "Immutable Data Collections", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/facebook/immutable-js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
318602
7158