Namespace SC.Store

Extends: SC.Object
Defined in: frameworks/sproutcore/models/store.js
Availability: since SproutCore 1.0

The Store is where you can find all of your records. You should also use this to define your various types of records, since this will be used to automatically update from data coming from the server.

You should create a store for each application. This allows the records for apps to be kept separate, even if they live in the same page.

Properties borrowed from class SC.Object:
isClass, isObject, outlets

Method Summary

Methods borrowed from class SC.Object:
$super, awake, create, createArray, extend, init, instanceOf, invokeLater, keys, kindOf, mixin, objectClassName, outlet, respondsTo, tryToPerform
Methods borrowed from class SC.Observable:
addObserver, allPropertiesDidChange, automaticallyNotifiesObserversFor, beginPropertyChanges, bind, decrementProperty, didChangeFor, endPropertyChanges, get, getEach, getPath, incrementProperty, logProperty, notifyPropertyChange, observeOnce, propertyDidChange, propertyObserver, propertyWillChange, registerDependentKey, set, setIfChanged, setPath, toggleProperty, unknownProperty

Method Details

addRecord()

Add a record instance to the store.

-   addRecord (rec)

Discussion

The record will now be monitored for changes.

findRecords()

You can pass any number of condition hashes to this, ending with a recordType.

-   findRecords ()

Discussion

It will AND the results of each condition hash.

getRecordFor()

finds the record with the primary key value.

-   getRecordFor (pkValue, recordType, dontAutoaddRecord)

Discussion

If the record does not exist, creates it.

records()

Returns an array of all records in the store.

-   records ()

Discussion

Mostly used for storing.

relocateRecord()

Since records are cached by primaryKey, whenever that key changes we need to re-cache it in the proper place

-   SC.Record  relocateRecord (oldkey, newkey, rec)

Parameters
string oldkey
string newkey
SC.Record rec
Return Value

SC.Record - 

Discussion

removeRecord()

remove a record instance from the store.

-   removeRecord (rec)

Discussion

The record will no longer be monitored for changes and may be deleted.

updateRecords()

Pushes updated data to all the named records.

-   Array  updateRecords (dataHashes, dataSource, recordType, isLoaded)

Parameters
dataHashes

See discussion.

dataSource

Usually a server object.

recordType
isLoaded

NO otherwise.

Return Value

Array - 

Discussion

This method is often called from a server to update the store with the included record objects.

You can use this method yourself to mass update the store whenever you retrieve new records from the server. The first parameter should contain an array of JSON-compatible hashes. The hashes can have any properties you want but they should at least contain the following two keys:

  • guid: This is a unique identifier for the record.
  • type: The name of the record type. I.e. "Contact" or "Photo"
Documentation generated by JsDoc Toolkit 2.0.1 on Tue Aug 12 2008 03:11:24 GMT-0700 (PDT)