classReadOnlyRootCollection
Source: read-only-root-collection.
Represents the definition of an asynchronous read-only root collection.
Properties
Methods
new ReadOnlyRootCollection([eventHandlers])
Creates a new asynchronous read-only root collection instance.
The name of the model type available as: <instance>.constructor.modelType, returns 'ReadOnlyRootCollection'.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
eventHandlers |
Yes |
The event handlers of the instance. |
- Extends
- CollectionBase
- Fires
- ReadOnlyRootCollection#event:preFetch
- ReadOnlyRootCollection#event:postFetch
- Throws
-
Argument error: The event handlers must be an EventHandlerList object or null.
Properties
read-only$modelName
string
The name of the model.
read-onlycount
number
The count of the child objects in the collection.
read-onlytotalItems
number
The count of all available items if provided by the data access object.
Methods
staticfetch([filter][, method][, eventHandlers], callback)
Retrieves a read-only business object collection from the repository.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
filter |
any type |
Yes |
The filter criteria. |
method |
string |
Yes |
An alternative fetch method of the data access object. |
eventHandlers |
Yes |
The event handlers of the instance. |
|
callback |
|
Returns the required read-only collection. |
- Throws
-
Argument error: The method must be a string or null.
-
Argument error: The event handlers must be an EventHandlerList object or null.
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Fetching the business object collection has failed.
at(index) → ReadOnlyChildModel
Gets a collection item at a specific position.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
index |
number |
|
The index of the required item in the collection. |
- Returns
-
ReadOnlyChildModel
The required collection item.
checkRules()
Executes all the validation rules of all business objects in the collection, including the ones of their child objects.
By default read-only business object collections are supposed to be valid.
every(callback) → boolean
Tests whether all items in the collection pass the test implemented by the provided function.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callback |
|
Function to test for each collection item. |
- Returns
-
boolean
True when callback returns truthy value for each item, otherwise false.
protectedfetch([filter][, method], callback)
Initializes a business object collection to be retrieved from the repository.
This method is called by a factory method with the same name.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
filter |
any type |
Yes |
The filter criteria. |
method |
string |
Yes |
An alternative fetch method of the data access object. |
callback |
|
Returns the required read-only collection. |
- Throws
-
Argument error: The method must be a string or null.
-
Argument error: The callback must be a function.
-
Authorization error: The user has no permission to execute the action.
-
Data portal error: Fetching the business object has failed.
filter(callback) → Array of ReadOnlyChildModel
Creates a new array with all collection items that pass the test implemented by the provided function.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callback |
|
Function to test for each collection item. |
- Returns
-
Array of ReadOnlyChildModel
The new array of collection items.
forEach(callback)
Executes a provided function once per collection item.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callback |
|
Function that produces an item of the new collection. |
getBrokenRules([namespace]) → bo.rules.BrokenRulesOutput
Gets the broken rules of the business object collection.
By default read-only business object collections are supposed to be valid.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
namespace |
string |
Yes |
The namespace of the message keys when messages are localizable. |
- Returns
-
bo.rules.BrokenRulesOutput
The broken rules of the business object collection.
getResponse([message][, namespace]) → bo.rules.BrokenRulesResponse
Gets the response to send to the client in case of broken rules.
By default read-only business object collections are supposed to be valid.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
message |
string |
Yes |
Human-readable description of the reason of the failure. |
namespace |
string |
Yes |
The namespace of the message keys when messages are localizable. |
- Returns
-
bo.rules.BrokenRulesResponse
The broken rules response to send to the client.
isValid() → boolean
Indicates whether all the validation rules of the business objects in the collection, including the ones of their child objects, succeeds. A valid collection may have broken rules with severity of success, information and warning.
By default read-only business object collections are supposed to be valid.
- Returns
-
boolean
True when the business object is valid, otherwise false.
map(callback) → Array of any type
Creates a new array with the results of calling a provided function on every item in this collection.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callback |
|
Function to test for each collection item. |
- Returns
-
Array of any type
The new array of callback results.
some(callback) → boolean
Tests whether some item in the collection pass the test implemented by the provided function.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
callback |
|
Function to test for each collection item. |
- Returns
-
boolean
True when callback returns truthy value for some item, otherwise false.
sort([fnCompare]) → ReadOnlyRootCollection
Sorts the items of the collection in place and returns the collection.
Parameter
Name | Type | Optional | Description |
---|---|---|---|
fnCompare |
Yes |
Function that defines the sort order. If omitted, the collection is sorted according to each character's Unicode code point value, according to the string conversion of each item. |
- Returns
-
ReadOnlyRootCollection
The sorted collection.
toCto() → Array of object
Transforms the business object collection to a plain object array to send to the client.
- Returns
-
Array of object
The client transfer object.
Events
postFetch
The event arises after the collection instance has been retrieved from the repository.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
eventArgs |
|
Data portal event arguments. |
|
newObject |
|
The collection instance after the data portal action. |
preFetch
The event arises before the collection instance will be retrieved from the repository.
Parameters
Name | Type | Optional | Description |
---|---|---|---|
eventArgs |
|
Data portal event arguments. |
|
oldObject |
|
The collection instance before the data portal action. |