Global

Members

load

Loads the model.$relation variable with what is necessary to get, set, relate, and unrelate models. If property is true, look at model[ name ] to load models/keys. If it contains values that don't exist or aren't actually related

WheresObject

A map of saved whereCallback functions.

Methods

all(success, failure)

Returns all records and their keys to the given success callback.

Name Type Description
success function

The function to invoke with the array of records and an array of keys.

failure function

The function to invoke with the error that occurred if available.

buildKeyFromInput(input){Any}

Builds a key from input. Discriminated collections only accept objects as input - otherwise there's no way to determine the discriminator. If the discriminator on the input doesn't map to a Rekord instance OR the input is not an object the input will be returned instead of a model instance.

Name Type Description
input modelInput

The input to create a key for.

Returns:
Type Description
Any - The built key or the given input if a key could not be built.

Documented in Collection.js

Documented in Collection.js

DiscriminateCollection(collection, discriminator, discriminatorsToModel){Rekord.ModelCollection}

Overrides functions in the given model collection to turn it into a collection which contains models with a discriminator field.

Name Type Description
collection Rekord.ModelCollection

The collection instance with discriminated models.

discriminator String

The name of the field which contains the discriminator.

discriminatorsToModel Object

A map of discriminators to the Rekord instances.

Returns:
Type Description
Rekord.ModelCollection - The reference to the given collection.

filter(callback, dest){Rekord.Map}

Passes all values & keys in this map to a callback and if it returns a truthy value then the key and value are placed in the destination map.

Name Type Description
callback function

[description]

dest Rekord.Map optional

[description]

Returns:
Type Description
Rekord.Map [description]

get(key){V}

Returns the value mapped by the given key.

Name Type Description
key String
Returns:
Type Description
V

Handles the ModelUpdated event from the database.

has(key){Boolean}

Returns whether this map has a value for the given key.

Name Type Description
key String
Returns:
Type Description
Boolean

init(database, field, options)

Initializes this relation with the given database, field, and options.

Name Type Description
database Rekord.Database

[description]

field String

[description]

options Object

[description]

Documented in Collection.js

isSorted(comparator){Boolean}

Name Type Description
comparator function

[description]

Returns:
Type Description
Boolean [description]

off(eventsInput, callback)

Stops listening for a given callback for a given set of events.

Examples:

target.off();           // remove all listeners
target.off('a b');      // remove all listeners on events a & b
target.off(['a', 'b']); // remove all listeners on events a & b
target.off('a', x);     // remove listener x from event a
Name Type Description
eventsInput String | Array | Object optional
callback function optional

onInitialized()

Takes input and returns a model instance. The input is expected to be an object, any other type will return null.

Name Type Default Description
input modelInput

The input to parse to a model instance.

remoteData Boolean false optional

Whether or not the input is coming from a remote source.

Returns:
Type Description
Rekord.Model - The model instance parsed or null if none was found.

put(key, value){Rekord.Map}

Puts the value in the map by the given key.

Name Type Description
key String
value V
Returns:
Type Description
Rekord.Map - The reference to this map.

put(key, record, success, failure)

Places a record in the store with the given key.

Name Type Description
key String | Number

The key to store the record as.

record Object

The record to store.

success function

A function to invoke when the record is successfully stored with the key. The arguments of the function should be the key and record passed to this function.

failure function

A function to invoke when the record failed to be stored with the key. The arguments of the function should be the key, record, and an error that occurred if available.

rebuildIndex(){Rekord.Map}

Rebuilds the index based on the keys.

Returns:
Type Description
Rekord.Map - The reference to this map.

remove(key, success, failure)

Removes a record from the store with the given key.

Name Type Description
key String | Number

The key to remove from the store.

success function

A function to invoke when the record doesn't exist in the store. The arguments of the function are the removedValue (if any) and the key passed to this function.

failure function

A function to invoke when there was an issue removing the key from the store. The arguments of the function are the key given to this function and an error that occurred if available.

remove(key){Rekord.Map}

Removes the value by a given key

Name Type Description
key String
Returns:
Type Description
Rekord.Map - The reference to this map.

removeAt(index){Rekord.Map}

Removes the value & key at the given index.

Name Type Description
index Number
Returns:
Type Description
Rekord.Map - The reference to this map.

Resets the map by initializing the values, keys, and indexes.

Returns:
Type Description
Rekord.Map - The reference to this map.

reset(keys, records, success, failure)

Resets the store so it contains ONLY the given keys & record pairs.

Name Type Description
keys Array.<String>

The array of keys.

records Array.<Object>

The array of records to save.

success function

The function to invoke with the array of records and an array of keys.

failure function

The function to invoke with the error that occurred if available.

reverse(){Rekord.Map}

Reverses the order of the underlying values & keys.

Returns:
Type Description
Rekord.Map - The referense to this map.

setModelReference()

size(){Number}

Returns the number of elements in the map.

Returns:
Type Description
Number

sort(comparator){Map}

Sorts the underlying values & keys given a value compare function.

Name Type Description
comparator function

A function which accepts two values and returns a number used for sorting. If the first argument is less than the second argument, a negative number should be returned. If the arguments are equivalent then 0 should be returned, otherwise a positive number should be returned.

Returns:
Type Description
Map - The reference to this map.

Documented in Collection.js

Documented in Collection.js

See:

trigger(eventsInput, args)

Triggers a single event optionally passing an argument to any listeners.

Name Type Description
eventsInput String
args Array

Type Definitions

comparatorInputString comparisonCallback Array

A string, a function, or an array of mixed values.

'age'                   // age property of an object
'-age'                  // age property of an object, ordering reversed
function(a, b) {}       // a function which compares two values
['age', 'done']         // age property of an object, and when equal, the done value
'creator.name'          // name sub-property of creator property
'{creator.name}, {age}' // formatted string

comparisonCallback(a, b){Number}

A function for comparing two values to determine if one is greater or lesser than the other or if they're equal.

comparisonCallback( a, b ) < 0 // a < b
comparisonCallback( a, b ) > 0 // a > b
comparisonCallback( a, b ) == 0 // a == b
Name Type Description
a Any

The first value to test.

b Any

The second value to test.

See:
  • Rekord.compare
  • Rekord.compareNumbers
Returns:
Type Description
Number - 0 if the two values are considered equal, a negative value if a is considered less than b, and a positive value if a is considered greater than b.

equalityCallback(a, b){Boolean}

A function for comparing two values and determine whether they're considered equal.

Name Type Description
a Any

The first value to test.

b Any

The second value to test.

See:
  • Rekord.equals
  • Rekord.equalsStrict
  • Rekord.equalsCompare
Returns:
Type Description
Boolean - Whether or not the two values are considered equivalent.

modelInput()

A value which identifies a model instance. This can be the key of the model, an array of values (if the model has composite keys), an object which at least contains fields which identify the model, an instance of a model, the reference to a Rekord instance, or a function.

If a plain object is given and it shares the same key as an existing model - the other fields on the object will be applied to the existing instance. If a plain object is given and it's key doesn't map to an existing model - a new one is created.

If a reference to a Rekord instance is given - a new model instance is created with default values.

If a function is given - it's invoked and the returning value is used as the value to identify the model instance.

modelKeyString Number

A key to a model instance.

propertyResolverCallback(model){Any}

A function for resolving a value from a given value. Typically used to transform an object into one of it's properties.

Name Type Description
model Any

The model to use to resolve a value.

See:
Returns:
Type Description
Any - The resolved value.

propertyResolverInput()

An expression which resolves a value from another value.

// {age: 6, name: 'x', user: {first: 'tom'}}
'age'                    // age property of an object
'user.first'             // sub property
'{age}, {user.first}'    // a formatted string built from object values
function(a) {}           // a function which returns a value itself
['age', 'name']          // multiple properties joined with a delimiter
{age:null, user:'first'} // multiple properties joined with a delimiter including a sub property

searchOptionsObject

Options you can pass to Rekord.Search or Rekord.Model.search.

Properties:
Name Type Argument Description
$encode function <optional>

A function which converts the search into an object to pass to the specified methods.

$decode function <optional>

A function which takes the data returned from the server and returns The array of models which are to be placed in the Rekord.Search#$results property.

searchPageOptionsObject

Options you can pass to Rekord.SearchPaged or Rekord.Model.searchPaged.

Properties:
Name Type Argument Default Description
page_size Number <optional>
10

The size of the pages.

page_index Number <optional>
0

The index of the search page.

total Number <optional>
0

The total number of models that exist in the search without pagination

  • this is expected to be provided by the remote search response.
$encode function <optional>

A function which converts the search into an object to pass to the specified methods.

$decode function <optional>

A function which takes the data returned from the server and updates this search with the results and paging information.

$decodeResults function <optional>

A function which takes the data returned from the server and returns the array of models which are to be placed in the Rekord.Search#$results property.

$updatePageSize function <optional>

A function which takes the data returned from the server and sets an updated page size of the search.

$updatePageIndex function <optional>

A function which takes the data returned from the server and sets an updated page index of the search.

$updateTotal function <optional>

A function which takes the data returned from the server and sets an updated total of the search.

whereCallback(value){Boolean}

A function which takes a value (typically an object) and returns a true or false value.

Name Type Description
value Any

The value to test.

See:
Returns:
Type Description
Boolean - Whether or not the value passed the test.

whereInputString Object Array whereCallback

An expression which can be used to generate a function for testing a value and returning a boolean result. The following types can be given and will result in the following tests:

  • String: If a string & value are given - the generated function will test if the object has a property with the given value. If a string is given and no value is given - the generated function will test if the object has the property and a non-null value.
  • Object: If an object is given - the generated function will test all properties of the given object and return true only if the object being tested has the same values.
  • Array: If an array is given - each element in the array is passed as arguments to generate a new function. The returned function will only return true if all generated functions return true - otherwise false.
  • whereCallback: A function can be given which is immediately returned as the test function.