From 1577075e52e6bd65d182b4d8cc5fb2bb4c92c52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89velyne=20Lachance?= Date: Sun, 26 Jun 2016 00:30:24 -0400 Subject: [PATCH] Cache now returns `null` when using get(cacheID) with invalid ID (#441) * Cache now returns `null` when using get(cacheID) where the ID is invalid. * Documented `get(id)` * Adjusted version in conf.py to 8.0.0 --- docs/conf.py | 4 ++-- docs/docs_cache.rst | 4 ++++ lib/Util/Cache.js | 2 ++ src/Util/Cache.js | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 2041ce63b..d32fea76c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ author = u'hydrabolt' # built documents. # # The short X.Y version. -version = '7.0.1' +version = '8.0.0' # The full version, including alpha/beta/rc tags. -release = '7.0.1' +release = '8.0.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/docs_cache.rst b/docs/docs_cache.rst index f1d7a6a39..e46095ebd 100644 --- a/docs/docs_cache.rst +++ b/docs/docs_cache.rst @@ -25,6 +25,10 @@ get(key, value) Returns a contained object where ``object[key] == value``. Also works if value is a regex or a function. Returns the first object found that matches the criteria. +get(value) + +Returns a contained object where ``object["id"] == value``. Shorthand for ``get("id", value)``. Returns ``null`` if ID is not found. + getAll(key, value) ~~~~~~~~~~~~~~~~~~ diff --git a/lib/Util/Cache.js b/lib/Util/Cache.js index 1ed6a545f..cd11d7ced 100644 --- a/lib/Util/Cache.js +++ b/lib/Util/Cache.js @@ -25,6 +25,8 @@ var Cache = (function (_Array) { if (typeof key === 'function') { var valid = key; key = null; + } else if (key && !value) { + return this[discrimCacheS][key] || null; } else if (key === this[discrimS] && typeof value === "string") { return this[discrimCacheS][value] || null; } else if (value && value.constructor.name === 'RegExp') { diff --git a/src/Util/Cache.js b/src/Util/Cache.js index 31b98011c..a37f4c0f2 100644 --- a/src/Util/Cache.js +++ b/src/Util/Cache.js @@ -15,6 +15,8 @@ export default class Cache extends Array { if (typeof key === 'function') { var valid = key; key = null; + } else if (key && !value) { + return this[discrimCacheS][key] || null; } else if (key === this[discrimS] && typeof value === "string") { return this[discrimCacheS][value] || null; } else if (value && value.constructor.name === 'RegExp') {