mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-20 13:33:30 +01:00
Documented Cache
This commit is contained in:
39
docs/docs_cache.rst
Normal file
39
docs/docs_cache.rst
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
.. include:: ./vars.rst
|
||||||
|
|
||||||
|
Cache
|
||||||
|
=====
|
||||||
|
|
||||||
|
A Cache object extends an Array (so it can be used like a regular array) but introduces helper functions to make it more useful when developing with discord.js. Unlike a regular array, it doesn't care about the instance or prototype of an object, it works purely on properties.
|
||||||
|
|
||||||
|
Functions
|
||||||
|
---------
|
||||||
|
|
||||||
|
get(key, value)
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Returns a contained object where ``object[key] == value``. Returns the first object found that matches the criteria.
|
||||||
|
|
||||||
|
getAll(key, value)
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Similar to ``cache.get(key, value)``, but returns a Cache of any objects that meet the criteria.
|
||||||
|
|
||||||
|
has(key, value)
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Returns `true` if there is an object that meets the condition ``object[key] == value`` in the cache
|
||||||
|
|
||||||
|
add(data)
|
||||||
|
~~~~~~~~~
|
||||||
|
|
||||||
|
Adds an object to the Cache as long as all the other objects in the cache don't have the same ID as it.
|
||||||
|
|
||||||
|
update(old, data)
|
||||||
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Updates an old object in the Cache (if it exists) with the new one.
|
||||||
|
|
||||||
|
remove(data)
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Removes an object from the cache if it exists.
|
||||||
@@ -24,6 +24,12 @@ Contents:
|
|||||||
:caption: Documentation
|
:caption: Documentation
|
||||||
|
|
||||||
docs_client
|
docs_client
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 2
|
||||||
|
:caption: Util Documentation
|
||||||
|
|
||||||
|
docs_cache
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
Indices and tables
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
.. _Client : ./docs_client.html
|
.. _Client : ./docs_client.html
|
||||||
|
.. _Cache : ./docs_cache.html
|
||||||
.. _Promises : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
.. _Promises : https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||||
@@ -22,7 +22,7 @@ class Cache extends Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAll(key, value) {
|
getAll(key, value) {
|
||||||
var found = [];
|
var found = new Cache(this.discrim);
|
||||||
this.forEach((val, index, array) => {
|
this.forEach((val, index, array) => {
|
||||||
if (val.hasOwnProperty(key) && val[key] == value) {
|
if (val.hasOwnProperty(key) && val[key] == value) {
|
||||||
found.push(val);
|
found.push(val);
|
||||||
|
|||||||
Reference in New Issue
Block a user