Constructor
new Document()
Creates a new Document instance. Documents allow you to create individual
objects that can have standard ForerunnerDB CRUD operations run against
them, as well as data-binding if the AutoBind module is included in your
project.
- Source:
Methods
(private, static) _isPositionalKey(key) → {Boolean}
Determines if the passed key has an array positional mark (a dollar at the end
of its name).
Parameters:
Name | Type | Description |
---|---|---|
key |
String | The key to check. |
- Source:
Returns:
True if it is a positional or false if not.
- Type
- Boolean
(private, static) _updateIncrement(doc, prop, val)
Increments a value for a property on a document by the passed number.
Parameters:
Name | Type | Description |
---|---|---|
doc |
Object | The document to modify. |
prop |
String | The property to modify. |
val |
Number | The amount to increment by. |
- Source:
(private, static) _updateMultiply(doc, prop, val)
Multiplies a value for a property on a document by the passed number.
Parameters:
Name | Type | Description |
---|---|---|
doc |
Object | The document to modify. |
prop |
String | The property to modify. |
val |
Number | The amount to multiply by. |
- Source:
(private, static) _updateProperty(doc, prop, val)
Updates a property on an object depending on if the collection is
currently running data-binding or not.
Parameters:
Name | Type | Description |
---|---|---|
doc |
Object | The object whose property is to be updated. |
prop |
String | The property to update. |
val |
* | The new value of the property. |
- Source:
(private, static) _updatePull(arr, index)
Removes an item from the passed array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | The array to modify. |
index |
Number | The index of the item in the array to remove. |
- Source:
(private, static) _updatePush(arr, doc)
Inserts an item at the end of an array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | The array to insert the item into. |
doc |
Object | The document to insert. |
- Source:
(private, static) _updateRename(doc, prop, val)
Renames a property on a document to the passed property.
Parameters:
Name | Type | Description |
---|---|---|
doc |
Object | The document to modify. |
prop |
String | The property to rename. |
val |
Number | The new property name. |
- Source:
(private, static) _updateSpliceMove(arr, indexFrom, indexTo)
Changes the index of an item in the passed array.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | The array to modify. |
indexFrom |
Number | The index to move the item from. |
indexTo |
Number | The index to move the item to. |
- Source:
(private, static) _updateSplicePush(arr, index, doc)
Inserts an item into the passed array at the specified index.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | The array to insert into. |
index |
Number | The index to insert at. |
doc |
Object | The document to insert. |
- Source:
(private, static) _updateUnset(doc, prop)
Deletes a property on a document.
Parameters:
Name | Type | Description |
---|---|---|
doc |
Object | The document to modify. |
prop |
String | The property to delete. |
- Source:
(static) db(dbopt) → {*}
Gets / sets the db instance this class instance belongs to.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
db |
Db |
<optional> |
The db instance. |
- Source:
Returns:
- Type
- *
(static) drop() → {boolean}
Drops the document.
- Source:
Returns:
True if successful, false if not.
- Type
- boolean
(static) find(query, optionsopt) → {Object}
Gets the document's data returned as a single object.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
query |
Object | The query object - currently unused, just provide a blank object e.g. {} | |
options |
Object |
<optional> |
An options object. |
- Source:
Returns:
The document's data object.
- Type
- Object
(static) isLinked() → {Boolean}
Checks if the instance is data-bound to any DOM elements.
- Source:
Returns:
True if linked, false if not.
- Type
- Boolean
(static) link(outputTargetSelector, templateSelector, optionsopt)
Creates a link to the DOM between the document data and the elements
in the passed output selector. When new elements are needed or changes
occur the passed templateSelector is used to get the template that is
output to the DOM.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
outputTargetSelector |
|||
templateSelector |
|||
options |
Object |
<optional> |
An options object. |
- Source:
- See:
-
- unlink
(static) name(valopt) → {*}
Gets / sets the document name.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
val |
String |
<optional> |
The name to assign |
- Source:
Returns:
- Type
- *
(static) setData(data, options) → {Document}
Sets the data for the document.
Parameters:
Name | Type | Description |
---|---|---|
data |
||
options |
- Source:
Returns:
- Type
- Document
(static) state(valopt) → {*}
Gets / sets the current state.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
val |
String |
<optional> |
The name of the state to set. |
- Source:
Returns:
- Type
- *
(static) unlink(outputTargetSelector, templateSelector)
Removes a link to the DOM between the document data and the elements
in the passed output selector that was created using the link() method.
Parameters:
Name | Type | Description |
---|---|---|
outputTargetSelector |
||
templateSelector |
- Source:
- See:
-
- link
(static) update(query, update, optionsopt) → {Array}
Modifies the document. This will update the document with the data held in 'update'.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
query |
Object | The query that must be matched for a document to be operated on. | |
update |
Object | The object containing updated key/values. Any keys that match keys on the existing document will be overwritten with this data. Any keys that do not currently exist on the document will be added to the document. | |
options |
Object |
<optional> |
An options object. |
- Source:
Returns:
The items that were updated.
- Type
- Array
(private, static) updateObject(doc, update, query, options, path, opType) → {Boolean}
Internal method for document updating.
Parameters:
Name | Type | Description |
---|---|---|
doc |
Object | The document to update. |
update |
Object | The object with key/value pairs to update the document with. |
query |
Object | The query object that we need to match to perform an update. |
options |
Object | An options object. |
path |
String | The current recursive path. |
opType |
String | The type of update operation to perform, if none is specified default is to set new data against matching fields. |
- Source:
Returns:
True if the document was updated with new / changed data or
false if it was not updated because the data was the same.
- Type
- Boolean