Constructor
(abstract) new WorldCollection(data)
- See:
Parameters:
Name | Type | Description |
---|---|---|
data |
Array.<object> | An array of data objects from which to create Document instances |
Extends
Members
(static) instance :WorldCollection
Return a reference to the singleton instance of this WorldCollection, or null if it has not yet been created.
Type:
(static) registeredSheets :Array.<DocumentSheet>
Return an array of currently registered sheet classes for this Document type.
Type:
apps :Array.<Application>
- Overrides:
An Array of application references which will be automatically updated when the collection content changes
Type:
contents :Array.<*>
- Overrides:
Return an Array of all the entry values in the Collection
Type:
- Array.<*>
directory :SidebarDirectory
Return a reference to the SidebarDirectory application for this WorldCollection.
Type:
documentClass :function
- Overrides:
A reference to the Document class definition which is contained within this DocumentCollection.
Type:
- function
documentName :string|null
- Overrides:
The base Document type which is contained within this WorldCollection
Type:
- string | null
name :string
- Overrides:
The Collection class name
Type:
- string
Methods
(static) registerSheet()
Register a Document sheet class as a candidate which can be used to display Documents of a given type. See DocumentSheetConfig.registerSheet for details.
Example
Register a new ActorSheet subclass for use with certain Actor types.
Actors.registerSheet("dnd5e", ActorSheet5eCharacter, { types: ["character], makeDefault: true });
(static) unregisterSheet()
Unregister a Document sheet class, removing it from the list of available sheet Applications to use. See DocumentSheetConfig.unregisterSheet for detauls.
Example
Deregister the default ActorSheet subclass to replace it with others.
Actors.unregisterSheet("core", ActorSheet);
(protected) _onCreateDocuments(documents, result, options, userId)
- Overrides:
Follow-up actions taken after a set of Documents in this Collection are created.
Parameters:
Name | Type | Description |
---|---|---|
documents |
Array.<Document> | An Array of created Documents |
result |
Array.<object> | An Array of created data objects |
options |
object | Options which modified the creation operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _onDeleteDocuments(documents, result, options, userId)
- Overrides:
Follow-up actions taken after a set of Documents in this Collection are deleted.
Parameters:
Name | Type | Description |
---|---|---|
documents |
Array.<Document> | An Array of deleted Documents |
result |
Array.<string> | An Array of document IDs being deleted |
options |
object | Options which modified the deletion operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _onUpdateDocuments(documents, result, options, userId)
- Overrides:
Follow-up actions taken after a set of Documents in this Collection are updated.
Parameters:
Name | Type | Description |
---|---|---|
documents |
Array.<Document> | An Array of updated Documents |
result |
Array.<object> | An Array of incremental data objects |
options |
object | Options which modified the update operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _preCreateDocuments(result, options, userId)
- Overrides:
Preliminary actions taken before a set of Documents in this Collection are created.
Parameters:
Name | Type | Description |
---|---|---|
result |
Array.<object> | An Array of created data objects |
options |
object | Options which modified the creation operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _preDeleteDocuments(result, options, userId)
- Overrides:
Preliminary actions taken before a set of Documents in this Collection are deleted.
Parameters:
Name | Type | Description |
---|---|---|
result |
Array.<string> | An Array of document IDs being deleted |
options |
object | Options which modified the deletion operation |
userId |
string | The ID of the User who triggered the operation |
(protected) _preUpdateDocuments(result, options, userId)
- Overrides:
Preliminary actions taken before a set of Documents in this Collection are updated.
Parameters:
Name | Type | Description |
---|---|---|
result |
Array.<object> | An Array of incremental data objects |
options |
object | Options which modified the update operation |
userId |
string | The ID of the User who triggered the operation |
delete()
filter(condition) → {Array.<*>}
- Overrides:
- See:
-
- {Array#filter}
Filter the Collection, returning an Array of entries which match a functional condition.
Example
let c = new Collection([["a", "AA"], ["b", "AB"], ["c", "CC"]]);
let hasA = c.filters(entry => entry.slice(0) === "A");
Parameters:
Name | Type | Description |
---|---|---|
condition |
function | The functional condition to test |
Returns:
An Array of matched values
- Type
- Array.<*>
find(condition) → {*}
- Overrides:
- See:
-
- {Array#find}
Find an entry in the Map using an functional condition.
Example
let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
let a = c.find(entry => entry === "A");
Parameters:
Name | Type | Description |
---|---|---|
condition |
function | The functional condition to test |
Returns:
The value, if found, otherwise undefined
- Type
- *
forEach(fn)
- Overrides:
- See:
-
- Array#forEach
Apply a function to each element of the collection
Example
let c = new Collection([["a", {active: false}], ["b", {active: false}], ["c", {active: false}]]);
c.forEach(e => e.active = true);
Parameters:
Name | Type | Description |
---|---|---|
fn |
function | The function to apply |
fromCompendium(document, optionsopt) → {object}
Apply data transformations when importing a Document from a Compendium pack
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
document |
Document | object | The source Document, or a plain data object |
||||||||||||||||||||||||||
options |
object |
<optional> |
Additional options which modify how the document is imported Properties
|
Returns:
The processed data ready for world Document creation
- Type
- object
get(key, optionsopt) → {*|undefined}
- Overrides:
Get an element from the Collection by its key.
Example
let c = new Collection([["a", "Alfred"], ["b", "Bob"], ["c", "Cynthia"]]);
c.get("a"); // "Alfred"
c.get("d"); // undefined
c.get("d", {strict: true}); // throws Error
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
key |
string | The key of the entry to retrieve |
|||||||||||
options |
object |
<optional> |
Additional options that affect how entries are retrieved Properties
|
Returns:
The retrieved entry value, if the key exists, otherwise undefined
- Type
- * | undefined
getName(name, optionsopt) → {*}
- Overrides:
Get an entry from the Collection by name. Use of this method assumes that the objects stored in the collection have a "name" attribute.
Example
let c = new Collection([["a", "Alfred"], ["b", "Bob"], ["c", "Cynthia"]]);
c.getName("Alfred"); // "Alfred"
c.getName("D"); // undefined
c.getName("D", {strict: true}); // throws Error
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | The name of the entry to retrieve |
|||||||||||
options |
object |
<optional> |
Additional options that affect how entries are retrieved Properties
|
Returns:
The retrieved entry value, if one was found, otherwise undefined
- Type
- *
(async) importFromCompendium(pack, id, updateDataopt, optionsopt) → {Promise.<Document>}
Import a Document from a Compendium collection, adding it to the current World.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pack |
CompendiumCollection | The CompendiumCollection instance from which to import |
|
id |
string | The ID of the compendium entry to import |
|
updateData |
Object |
<optional> |
Optional additional data used to modify the imported Document before it is created |
options |
Object |
<optional> |
Optional arguments passed to the WorldCollection#fromCompendium and Document.create methods |
Returns:
The imported Document instance
- Type
- Promise.<Document>
map(transformer) → {Array.<*>}
- Overrides:
Transform each element of the Collection into a new form, returning an Array of transformed values
Parameters:
Name | Type | Description |
---|---|---|
transformer |
function | The transformation function to apply to each entry value |
Returns:
An Array of transformed values
- Type
- Array.<*>
reduce(evaluator, initial) → {any}
- Overrides:
- See:
-
- {Array#reduce}
Reduce the Collection by applying an evaluator function and accumulating entries
Example
let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
let letters = c.reduce((s, l) => {
return s + l;
}, ""); // "ABC"
Parameters:
Name | Type | Description |
---|---|---|
evaluator |
function | A function which mutates the accumulator each iteration |
initial |
any | An initial value which accumulates with each iteration |
Returns:
The accumulated result
- Type
- any
render()
- Overrides:
Render any Applications associated with this DocumentCollection.
set()
- Overrides:
some(condition) → {boolean}
- Overrides:
- See:
-
- {Array#some}
Test whether a condition is met by some entry in the Collection
Parameters:
Name | Type | Description |
---|---|---|
condition |
function | A test condition to apply to each entry |
Returns:
Was the test condition passed by at least one entry?
- Type
- boolean
toJSON() → {Array.<object>}
- Overrides:
Convert the Collection to a primitive array of its contents.
Returns:
An array of contained values
- Type
- Array.<object>
(async) updateAll(transformation, condition, optionsopt) → {Promise.<Array.<Document>>}
- Overrides:
Update all objects in this DocumentCollection with a provided transformation. Conditionally filter to only apply to Entities which match a certain condition.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
transformation |
function | object | An object of data or function to apply to all matched objects |
||
condition |
function | null |
null
|
A function which tests whether to target each object |
|
options |
object |
<optional> |
Additional options passed to Document.update |
Returns:
An array of updated data once the operation is complete
- Type
- Promise.<Array.<Document>>