The App.ObjectStore is responsible for all current state on the client. When the state of the store changes events are triggered based on what caused the change. All changes of the state should go through an method in the App.ObjectAction module to make sure listening components get notified of the state change.
There are 3 different type of events that can be listened for
change
is triggered when an object is editedcreated
is triggered when an object is createdreceived
is triggered when an object is received from the server
Example of listening to events
Example
// Object that has been changed
App.ObjectStore.addChangeEventListener(function(changedObjects) {
App.log.debug("Objects where changed", changedObjects);
});
// Object that has been created
App.ObjectStore.addCreatedEventListener(function(createdObjects) {
App.log.debug("Objects where created", createdObjectes);
});
// Object that has been received from the server
App.ObjectStore.addReceivedListener(function(receivedObjects) {
App.log.debug("Objects where received from the server", receivedObjects);
});
Methods
(static) addChangeListener(callback, listenerId, filterList)
Adds an change listener that will be notified when an change
event is triggered.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | that will be executed when an |
listenerId |
String | id. Will not be notified of change of its own events. (optional) |
filterList |
Array | ids of listeners that should be notified. (optional) |
(static) addCreateListener(callback, listenerId, filterList)
Adds an create listener that will be notified when an create
event is triggered.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | that will be executed when an |
listenerId |
String | id. Will not be notified of change of its own events. (optional) |
filterList |
Array | ids of listeners that should be notified. (optional) |
(static) addDeleteListener(callback, listenerId, filterList)
Adds an delete listener that will be notified when an delete
event is triggered.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | that will be executed when an |
listenerId |
String | id. Will not be notified of change of its own events. (optional) |
filterList |
Array | ids of listeners that should be notified. (optional) |
(static) addReceivedListener(callback, listenerId, filterList)
Adds an receive listener that will be notified when an receive
event is triggered.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | that will be executed when an |
listenerId |
String | id. Will not be notified of change of its own events. (optional) |
filterList |
Array | ids of listeners that should be notified. (optional) |
(static) clear()
Clears the store. All of the current state is cleared.
(static) count() → {Integer}
Returns the number of objects currently in the store
Returns:
Number of objects currently in the store
- Type
- Integer
(static) emitChange(objects, emitter)
Emits an change
event, that will notify listening components
Warning: This should be triggered by the App.Dispatcher, there should be no need to call this method directly
Parameters:
Name | Type | Description |
---|---|---|
objects |
Object | that have been changed |
emitter |
String | id of origin of event. Will not be notified of change if: listener is the emitter or if emitter was not on the filterList. |
(static) emitCreate(objects, emitter)
Emits an create event, that will notify listening components Warning: This should be triggered by the App.Dispatcher, there should be no need to call this method directly
Parameters:
Name | Type | Description |
---|---|---|
objects |
Object | that have been created |
emitter |
String | id of origin of event. Will not be notified of change if: listener is the emitter or if emitter was not on the filterList. |
(static) emitDelete(objects, emitter)
Emits an delete event, that will notify listening components Warning: This should be triggered by the App.Dispatcher, there should be no need to call this method directly
Parameters:
Name | Type | Description |
---|---|---|
objects |
Object | that have been deleted |
emitter |
String | id of origin of event. Will not be notified of change if: listener is the emitter or if emitter was not on the filterList. |
(static) emitReceive(objects, emitter)
Emits an receive event, i.e. when data is returned from the server, that will notify listening components Warning: This should be triggered by the App.Dispatcher, there should be no need to call this method directly
Parameters:
Name | Type | Description |
---|---|---|
objects |
Object | that have been received |
emitter |
String | id of origin of event. Will not be notified of change if: listener is the emitter or if emitter was not on the filterList. |
(static) get(objectId) → {Object}
Fetches the object associated with the passed in object id
Parameters:
Name | Type | Description |
---|---|---|
objectId |
String |
Returns:
Object associated with the passed in object id
- Type
- Object
(static) getAll() → {Object}
Fetches all of the currently stored objects
Returns:
Object An object containing everything currently in the store
- Type
- Object
(static) getAllRelationships() → {Object}
Fetches all of the currently stored relationships
Returns:
An object containing all relationships currently in the store
- Type
- Object
(static) getByIds(objectIds) → {Object}
Fetches the objects associated with the passed in object ids
Parameters:
Name | Type | Description |
---|---|---|
objectIds |
Array | of objects to be fetched |
Returns:
Object associated with the passed in object ids.
- Type
- Object
(static) getFromObject(relationshipId) → {Object}
Returns from object id associated with passed relationship id
Parameters:
Name | Type | Description |
---|---|---|
relationshipId |
String |
Returns:
from object
- Type
- Object
(static) getObjectRelationships(objectId) → {Object}
Fetches the Relationships associated with the passed in object id
Parameters:
Name | Type | Description |
---|---|---|
objectId |
String |
Returns:
Relationships associated with the passed in object id
- Type
- Object
(static) getRelationship(relationshipId) → {Object}
Returns object associated with the passed in relationship id
Parameters:
Name | Type | Description |
---|---|---|
relationshipId |
String |
Returns:
Object associated with the passed in relationship id
- Type
- Object
(static) getRelationshipByIds(relationshipIds) → {Object}
Fetches the relationships associated with the passed in object ids
Parameters:
Name | Type | Description |
---|---|---|
relationshipIds |
Array | of relationships to be fetched |
Returns:
Relationship associated with the passed in relationship ids.
- Type
- Object
(static) getToObject(relationshipId) → {Object}
Returns to object id associated with passed relationship id
Parameters:
Name | Type | Description |
---|---|---|
relationshipId |
String |
Returns:
from object
- Type
- Object
(static) removeChangeListener(callback, listenerId)
Parameters:
Name | Type | Description |
---|---|---|
callback |
||
listenerId |
(static) removeCreateListener(callback, listenerId)
Parameters:
Name | Type | Description |
---|---|---|
callback |
||
listenerId |
(static) removeDeleteListener(callback, listenerId)
Parameters:
Name | Type | Description |
---|---|---|
callback |
||
listenerId |
(static) validateByIds(ids, paths) → {Boolean}
Validates the objects associated with the passed in ids. All objects should have the properties defined by paths. Eg given object with id=123 and content: { a:{ b:false } } when validateByIds(['123'], ['a','a.b']) is called then returns true
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array | of objects to be fetched |
paths |
Array | An array of paths to the attributes that should be defined, like "a" or "a.b" |
Returns:
true if all objects exist with the properties defined in paths
- Type
- Boolean
(static) validateRelationshipsByIds(ids, paths) → {Boolean}
Validates the relationships associated with the passed in ids. All relationships should have the properties defined by paths. Eg given relationship with id=123 and content= { a:{ b:false } } when validateRelationshipsByIds(['123'], ['a','a.b']) is called then returns true
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array | of objects to be fetched |
paths |
Array | An array of paths to the attributes that should be defined, like "a" or "a.b" |
Returns:
true if all relationships exist with the properties defined in paths
- Type
- Boolean