new AliasedNameStore()
Members
-
_map :WeakMap
-
WeakMap for AliasedName => value internal storage. This is the only location that the full objects are actually held. Weakmaps are used on the event that garbage collection is needed. To fetch elements, use
classes.common.AliasedName.AliasedNameStore#get
and pass in a name/alias/id. -
_name_set :Set
-
Set for unique AliasedName storage. The size of this set should equal the number of unique elements in this AliasedNameStore. Mapping the values of this set to retrieve elements from
classes.common.AliasedName.AliasedNameStore#_map
can be used in lieu of get(). -
_names :Map
-
Map for key => AliasedName storage. This is where every alias and name is stored and points to all
classes.common.AliasedName.AliasedName
s used to retrieve elements. Duplicate names/aliases are not guaranteed to guaranteed to be preserved, however IDs, should they exist, will always point to the correct AliasedName object upon insertion and can be used inclasses.common.AliasedName.AliasedNameStore#get
. The size of this map cannot be used to check unique element count in this AliasedNameStore. -
fuzzy_options :Object
-
Options used to fuzzy-search for getting items from this storage.
- Default Value:
- undefined
- To Do:
-
- See todo for
classes.common.AliasedName.AliasedNameStore#get
.
- See todo for
-
Symbol.iterator
-
An iterator that yields all values in this AliasedNameStore.
-
type :Object
-
Type of elements in this AliasedNameStore. Can be used to enforce safety checks for insert operations to ensure that items stored are all of the same type. For a functional based approach, pass an object that defines [Symbol.hasInstance](obj).
- Default Value:
- undefined
Methods
-
__init__(id, opts) → {classes.common.AliasedName.AliasedNameStore}
-
Initializes this AliasedNameStore, optionally with pre-loading data.
Parameters:
Name Type Description id
string The id of this AliasedNameStore. opts
Object Options for this AliasedNameStore. Properties
Name Type Description data
classes.common.TrackingSet | Array | Set | undefined Optionally takes a TrackingSet compatible dataset to pre-load. fuzzy_options
Object | undefined classes.common.AliasedName.AliasedNameStore#fuzzy_options
.type
Object | undefined classes.common.AliasedName.AliasedNameStore#type
.Returns:
classes.common.AliasedName.AliasedNameStore - this -
delete(key, opts) → {boolean}
-
Removes an item from this AliasedNameStore. The methods delete and remove are identical.
Parameters:
Name Type Description key
string | classes.common.AliasedName.AliasedName The key to lookup a value for. All related keys will also be removed with the value. opts
Object Options for loading data into this AliasedNameStore Properties
Name Type Description safety
boolean NOT IMPLEMENTED: Whether to check if a value under the key exists before attempting to delete it. Returns:
boolean - True on success- To Do:
-
- Implement safety deletion check.
-
filter(cb) → {Array}
-
Similar to Array#filter. Calls the callback provided on every AliasedName stored inside this, and stores those values where cb returns true.
Parameters:
Name Type Description cb
function Callback called on every element in this storage. First arg is the item, second arg is its AliasedName key, and third is this storage. Function must return truthy for the value to be included in result. Returns:
Array - Filtered results of values from this AliasedNameStore.Example
Example usage of filtering.
filtered_arr = store.filter((item, name) => item.prop === 'value' && name.AKA() === 'something');
-
forEach(cb) → {undefined}
-
Similar to Array#forEach. Calls the callback provided on every AliasedName stored inside this. The methods each and forEach are identical.
Parameters:
Name Type Description cb
function Callback called on every element in this storage. First argument is the item, second arg is its AliasedName key, and third is this storage. Throws:
-
Aborts if an invalid name object has been found in this._map. AliasedNameStores should only store objects with an AliasedName #name property. The ID keys and stringified name aliases do not apply - we loop through this._name_set.
- Type
- Error
Returns:
undefined -
-
get(key, opts) → {*|undefined}
-
Gets an item from this AliasedNameStore by a key. Key could be a string as the name or alias of an
classes.common.AliasedName.AliasedName
, or an AliasedName object itself.Parameters:
Name Type Description key
string | classes.common.AliasedName.AliasedName The key to lookup a value for. opts
Object Options for this get operation. Properties
Name Type Description fuzzy_options
boolean NOT IMPLEMENTED: Whether to get using fuzzy options. Returns:
* | undefined - The value stored that matches key, otherwise undefined.- See:
-
- classes.common.AliasedName.AliasedName#set
- To Do:
-
- Implement fuzzy search.
-
get_all(keys, opts) → {Array.<(*|Object)>}
-
Gets many keys for items from this AliasedNameStore using
classes.common.AliasedName.AliasedNameStore#get
.Parameters:
Name Type Description keys
Array.<(string|classes.common.AliasedName.AliasedName)> The keys to lookup values for. opts
Object Options for each get operation. Returns:
Array.<(*|Object)> - The value stored that matches each key.- To Do:
-
- See todo for
classes.common.AliasedName.AliasedNameStore#get
.
- See todo for
-
insert(item, opts) → {boolean}
-
Adds an item to this AliasedNameStore. Retrieval of the item can be done by calling
classes.common.AliasedName.AliasedNameStore#get
and passing in item.name, item.name.name, any alias in item.name.for_every_alias, and item.id if the id exists on the item. The methods set and insert are identical.Parameters:
Name Type Description item
interfaces.IDNameCreatable The IDNameCreatable to add. Item must have a name property with an classes.common.AliasedName.AliasedName
opts
Object Options for loading data into this AliasedNameStore Properties
Name Type Description safety
boolean Whether to check data to load as being TrackingSet compatible Returns:
boolean - True on success -
load(data, opts) → {classes.common.AliasedName.AliasedNameStore}
-
Loads data in bulk into an AliasedNameStore
Parameters:
Name Type Description data
TrackingSet | Array | Set Takes a TrackingSet compatible dataset. opts
Object Options for loading data into this AliasedNameStore. Properties
Name Type Description safety
boolean Whether to check data to load as being TrackingSet compatible. Returns:
classes.common.AliasedName.AliasedNameStore - this -
map(cb) → {Array}
-
Similar to Array#map. Calls the callback provided on every AliasedName stored inside this, and stores the return values.
Parameters:
Name Type Description cb
function Callback called on every element in this storage. First arg is the item, second arg is its AliasedName key, and third is this storage. Returns:
Array - Filtered results of values from this AliasedNameStore.Example
Example usage of filtering.
filtered_arr = store.filter((item, name) => item.prop === 'value' && name.AKA() === 'something');
-
mget(keys, opts) → {Array.<(*|Object)>}
-
Gets many keys for items from this AliasedNameStore using
classes.common.AliasedName.AliasedNameStore#get
.Parameters:
Name Type Description keys
Array.<(string|classes.common.AliasedName.AliasedName)> The keys to lookup values for. opts
Object Options for each get operation. Returns:
Array.<(*|Object)> - The value stored that matches each key.- To Do:
-
- See todo for
classes.common.AliasedName.AliasedNameStore#get
.
- See todo for
-
remove(key, opts) → {boolean}
-
Removes an item from this AliasedNameStore. The methods delete and remove are identical.
Parameters:
Name Type Description key
string | classes.common.AliasedName.AliasedName The key to lookup a value for. All related keys will also be removed with the value. opts
Object Options for loading data into this AliasedNameStore Properties
Name Type Description safety
boolean NOT IMPLEMENTED: Whether to check if a value under the key exists before attempting to delete it. Returns:
boolean - True on success- To Do:
-
- Implement safety deletion check.
-
safe_get(key, opts) → {*|Object}
-
Gets an item from this AliasedNameStore by a key like
classes.common.AliasedName.AliasedNameStore#get
, except returns an empty object if the value cannot be found.Parameters:
Name Type Description key
string | classes.common.AliasedName.AliasedName The key to lookup a value for. opts
Object Options for this get operation. Properties
Name Type Description fuzzy_options
boolean NOT IMPLEMENTED: Whether to get using fuzzy options. Returns:
* | Object - The value stored that matches key, otherwise an empty object {}.- To Do:
-
- See todo for
classes.common.AliasedName.AliasedNameStore#get
.
- See todo for
-
safe_mget(keys, opts) → {Array.<(*|Object)>}
-
Safely gets many items from this AliasedNameStore using
classes.common.AliasedName.AliasedNameStore#safe_get
.Parameters:
Name Type Description keys
Array.<(string|classes.common.AliasedName.AliasedName)> The keys to lookup values for. opts
Object Options for each safe_get operation. Returns:
Array.<(*|Object)> - The value stored that matches each key.- To Do:
-
- See todo for
classes.common.AliasedName.AliasedNameStore#safe_get
.
- See todo for
-
set(item, opts) → {boolean}
-
Adds an item to this AliasedNameStore. Retrieval of the item can be done by calling
classes.common.AliasedName.AliasedNameStore#get
and passing in item.name, item.name.name, any alias in item.name.for_every_alias, and item.id if the id exists on the item. The methods set and insert are identical.Parameters:
Name Type Description item
interfaces.IDNameCreatable The IDNameCreatable to add. Item must have a name property with an classes.common.AliasedName.AliasedName
opts
Object Options for loading data into this AliasedNameStore Properties
Name Type Description safety
boolean Whether to check data to load as being TrackingSet compatible Returns:
boolean - True on success -
values(that) → {function}
-
Returns a values iterator for this AliasedNameStore.
Parameters:
Name Type Description that
string | classes.common.AliasedName.AliasedNameStore The AliasedNameStore to fetch the values iterator for. Returns:
function - The values iteratorExample
Example usage of looping through store.values() or implicit for/of with Symbol.iterator.
Array.from(store.values()).map(e => e.some_property_on_each_value); for (const v of store) {} for (const v of store.values()) {}
-
package, inner DefaultExports(deps) → {classes.common.AliasedName.AliasedNameStore}
-
Generates an AliasedNameStore class. Called internally within the AliasedName sub-folder assembly.
Parameters:
Name Type Description deps
Object Dependencies of the AliasedNameStore. Properties
Name Type Description AliasedName
classes.common.AliasedName.AliasedName Used for type safety checks and easy reference elsewhere via AliasedNameStore.AliasedName. IDCreatable
interfaces.IDCreatable The interface AliasedNameStore extends from. TrackingSet
classes.common.TrackingSet Used to check data being fed in bulk on AliasedNameStore creation. Returns:
classes.common.AliasedName.AliasedNameStore - The AliasedNameStore class