andalay

Option name Type Description
@property object

Andalay Model

@property object

Andalay Collection

return object

Andalay

Angular Andalay.

In a nutshell: Backbone-esc Models for Angular.

Andalay is essentially a fork of Backbone, with a few key differences.
1: No attributes array. The attributes are the model properties.
2: No events raised. Angular's two way data binding takes care of watching for data changes.

Show source

Model

constructor
Andalay.Model()

Option name Type Description
attributes Object

Initialize the record with these properties

options Object

Options object

return

void

Represents a singular model.
A collection contains an array of Andalay.Model objects.

new Andalay.Model({name:'steve'});
Show source

Andalay.Model

prototype
Andalay.Model.prototype

Option name Type Description
return

void

Define the Model's inheritable methods.

Show source

idAttribute

property
Andalay.Model.idAttribute

string Stores the name of the attribute (property) that the id value is stored in.

Show source

loading

property
Andalay.Model.loading

boolean whether the model is currently loading.

Show source

saving

property
Andalay.Model.saving

boolean whether the model is currently saving.

Show source

defaults

property
Andalay.Model.defaults

object define default attributes to set on this model.

Show source

initialize

method
Andalay.Model.prototype.initialize()

Initialize is an empty function by default. Override it with your own initialization logic.

Show source

toJSON

method
Andalay.Model.prototype.toJSON()

Option name Type Description
return object

Object consumable by JSON.stringify();

Returns an object that can be json-ified.

Show source

has

method
Andalay.Model.prototype.has()

Option name Type Description
property string

name

return boolean

Whether the model has a specified property.

Show source

parse

method
Andalay.Model.prototype.parse()

Option name Type Description
response object

The response from the server

options object
return object

The (altered) response

Parse converts a response into the hash of attributes to be set on the model.
The default implementation passes the response along.

Show source

isNew

method
Andalay.Model.prototype.isNew()

Option name Type Description
return boolean

Is the object new?

A model without an id attribute is considered to be new.

Show source

isValid

method
Andalay.Model.prototype.isValid()

Option name Type Description
return boolean

The result of validate()

Return the result of the model's validation function.

Show source

url

method
Andalay.Model.prototype.url()

Option name Type Description
return string

the url for the model resource

You can override this function to provide the url for this model resource.

Show source

validate

method
Andalay.Model.prototype.validate()

Option name Type Description
return boolean

The result of the validation rules. Defaults to true

Override this function to provide custom validation rules.

Show source

sync

method
Andalay.Model.prototype.sync()

Option name Type Description
return object

Promise object

A proxy to Andalay.sync().

Show source

fetch

method
Andalay.Model.prototype.fetch()

Option name Type Description
options type

Options object. If parse is set to false, the server response is not run through model.parse()

Fetch the model with its ID.

Show source

save

method
Andalay.Model.prototype.save()

Option name Type Description
Options object

object. validate: false prevents validation and forces save; defaults to true

return object

Promise object

Saves the current model to the backend.

Show source

delete

method
Andalay.Model.prototype.delete()

Option name Type Description
return object

Promise object

Delete the model on the server, and remove it from its parent collection.

Show source

setSaving

method
Andalay.Model.prototype.setSaving()

Option name Type Description
isSaving boolean

the state to set Model.saving

Sets the saving address.

Show source

Collection

method
Andalay.Collection()

Option name Type Description
models Array

Array of objects|models to add to the collection

options Object

Passing a model property sets the model property of the collection: MyCollection = new Andalay.Collection([{..}], {model:Andalay.Model})

return

void

Andalay.Collection

Represents a collection of Andalay.Model objects.
Creates a new Collection, to contain a specific type of Model.

Show source

Andalay.Collection

prototype
Andalay.Collection.prototype

Define the collection's inheritable methods.

Show source

model

property
Andalay.Collection.model

object The default model for a collection is just a Backbone.Model.
This should be overridden in most cases.

Show source

loading

property
Andalay.Collection.loading

boolean Whether the collection is currently loading.

Show source

saving

property
Andalay.Collection.saving

boolean Whether a model within the collection is currently saving.

Show source

models

property
Andalay.Collection.models

array Stores the list of models.

Show source

_index

property
Andalay.Collection._index

object Stores an indexed array of objects id:object and cid:object.

Show source

length

property
Andalay.Collection.length

int Mirrors the length of the models array.

Show source

initialize

method
Andalay.Collection.prototype.initialize()

Initialize is an empty function by default. Override it with your own initialization logic.

Show source

toJSON

method
Andalay.Collection.prototype.toJSON()

Option name Type Description
return object

Object consumable by JSON.stringify();

Returns an object that can be json-ified.

Show source

addOne

method
Andalay.Collection.prototype.addOne()

Option name Type Description
obj object

An object or a Model

options object

Options object. options.at (int) specifies the position to add the model in the collection

return object

The added object as an instance of the Model

Add a Model to the collection. If the model already exists in the collection, extend it.

Show source

parse

method
Andalay.Collection.prototype.parse()

Option name Type Description
response object

The response from the server

options object

Options object

return object

The (altered) response object

Parse converts a response into the hash of attributes to be set on the model.
The default implementation passes the response along.

Show source

addMany

method
Andalay.Collection.prototype.addMany()

Option name Type Description
models array

Array of objects to add

return array

An array of added or prexisting models

Add an array of objects to the collection.
It will merge if the object already exists and add if it does not.
For example:

var myCollection = Collection.addMany([{name:'test object'},{name:'another test object'}])
Show source

updateMany

method
Andalay.Collection.prototype.updateMany()

Option name Type Description
Array object

of objects to add

return array

An array of added or prexisting models

Proxy to addMany.

Show source

reset

method
Andalay.Collection.prototype.reset()

Option name Type Description
Array array

of objects to add

return array

Array of models that the collection has been reset to

When you have more items than you want to add or remove individually,
you can reset the entire set with a new list of models.

Show source

get

method
Andalay.Collection.prototype.get()

Option name Type Description
obj mixed

Pass in the id, the cid or an object. If passed an object it will attempt to get the id from the objects property specified by the model.idAttribute

return mixed

Andalay.Model | undefined

Get a model from the collection by id.

Show source

exists

method
Andalay.Collection.prototype.exists()

Option name Type Description
obj mixed

Pass in the id, the cid or an object.

return boolean

True if a model exists

Returns whether a model exists in the collection with the id.

Show source

update

method
Andalay.Collection.prototype.update()

Option name Type Description
obj object

An object or a Model

return object

The added object as an instance of the Model

Update a model.

Show source

remove

method
Andalay.Collection.prototype.remove()

Option name Type Description
Pass mixed

in the id, the cid or an object.

return mixed

The removed model, or undefined if no model found to remove.

Remove a model.

Show source

removeAll

method
Andalay.Collection.prototype.removeAll()

Option name Type Description
return object

this

Removes all models from the collection.

Show source

modelId

method
Andalay.Collection.prototype.modelId()

Option name Type Description
object object

Model

return mixed

string | interger

Returns the id value of the passed in Model.

Show source

last

method
Andalay.Collection.prototype.last()

Option name Type Description
return object

Model

Gets the last model in the collection.

Show source

at

method
Andalay.Collection.prototype.at()

Option name Type Description
index int

position of the Model

return object

Model

Returns the model at the specified position in the array.

Show source

size

method
Andalay.Collection.prototype.size()

Option name Type Description
return int

Size of the collection

Returns the size of the collection.

Show source

all

method
Andalay.Collection.prototype.all()

Option name Type Description
return Array

Array of models

Get all models in the collection as array.

Show source

where

method
Andalay.Collection.prototype.where()

Option name Type Description
attrs object

Object with attributes to match

first boolean

If true, returns the first model it matches

Return models with matching attributes. Useful for simple cases of filter.

Show source

findWhere

method
Andalay.Collection.prototype.findWhere()

Option name Type Description
attrs object

Object with attributes to match

Return the first model with matching attributes. Useful for simple cases of find.

Show source

sync

method
Andalay.Collection.prototype.sync()

Option name Type Description
return object

Promise object

A proxy to Andalay.sync().

Show source

fetch

method
Andalay.Collection.prototype.fetch()

Option name Type Description
options object

Options object

Fetch the default set of models for this collection from the server,
resetting the collection when they arrive. If reset: true is passed,
the response data will be passed through the reset() method instead of set().

Show source

_reset

method
Andalay.Collection.prototype._reset()

Private method to reset all internal state. Called when the collection
is first initialized or reset.

Show source

_prepareModel

method
Andalay.Collection.prototype._prepareModel()

Option name Type Description
object object

The would-be model.

return object

A bona fide model.

Prepare a hash of attributes (or other model) to be added to this
collection.

Show source

_addReference

method
Andalay.Collection.prototype._addReference()

Option name Type Description
model object

Model

return

void

Adds the model to the internal index (idIndex).
This essentially makes the collection aware of the model,
as it uses this index to search for models both by its autogenerated
client id and by its idAttribute if it exists and is not null.

Show source

_removeReference

method
Andalay.Collection.prototype._removeReference()

Option name Type Description
return

void

Removes all internal references to a model.

Show source

sync

method
Andalay.sync()

Option name Type Description
method string

The method to use

model object

The model to persist

options object

Options object. Pass in url or data to override. Additional options are passed to the $http service

return object

Promise generated by $http

The point at which Andalay interacts with the $http service to persist model data.

Show source

extend

function
extend()

Option name Type Description
protoProps object
staticProps object
return function

Constructor function

Create a subclass.
Shamelessly pinched from backbone.

Show source

extend

property
Andalay.Model.extend

Add extend function to Objects

Show source