You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _includes/js/local-datastore.md
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ const result = await query.get('xWMyZ4YE');
35
35
36
36
## Querying the Local Datastore
37
37
38
-
Often, you'll want to find a whole list of objects that match certain criteria, instead of getting a single object by id. To do that, you can use a [Parse.Query](#queries). Any `Parse.Query` can be used with the local datastore just as with the network. The results will include any object you have pinned that matches the query. Any unsaved changes you have made to the object will be considered when evaluating the query. So you can find a local object that matches, even if it was never returned from the server for this particular query. All query method are supported except aggregate and distinct queries.
38
+
Often, you'll want to find a whole list of objects that match certain criteria, instead of getting a single object by id. To do that, you can use a [Parse.Query](#queries). Any `Parse.Query` can be used with the local datastore just as with the network. The results will include any object you have pinned that matches the query. Any unsaved changes you have made to the object will be considered when evaluating the query. So you can find a local object that matches, even if it was never returned from the server for this particular query. All query methods are supported except aggregate and distinct queries.
Manually pinning and unpinning each object individual is a bit like using `malloc` and `free`. It is a very powerful tool, but it can be difficult to manage what objects get stored in complex scenarios. For example, imagine you are making a game with separate high score lists for global high scores and your friends' high scores. If one of your friends happens to have a globally high score, you need to make sure you don't unpin them completely when you remove them from one of the cached queries. To make these scenarios easier, you can also pin with a label. Labels indicate a group of objects that should be stored together.
70
+
Labels indicate a group of objects that should be stored together.
71
71
72
72
```javascript
73
73
// Add several objects with a label.
@@ -89,7 +89,7 @@ There's also a method to remove all objects from a label.
Any object will stay in the datastore as long as it is pinned with any label. In other words, if you pin an object with two different labels, and then unpin it with one label, the object will stay in the datastore until you also unpin it with the other label.
92
+
An Object will be kept in the datastore as long as it is pinned by at least one label. So an object pinned with two labelswill stay in the datastore if one of the two labels is unpinned.
93
93
94
94
## Caching Query Results
95
95
@@ -128,3 +128,19 @@ The local datastore is a dictionary of key / values. Each object has a key (clas
128
128
`pinWithName('YourPinName')` will save this reference under `parsePin_YourPinName`
129
129
130
130
Unpinning will have the opposite effect.
131
+
132
+
## LiveQuery
133
+
134
+
If you are subscribed to a LiveQuery Update Event, the updated object will be stored in the LocalDatastore if pinned.
135
+
136
+
```javascript
137
+
constgameScore=newGameScore();
138
+
awaitgameScore.save();
139
+
awaitgameScore.pin();
140
+
constquery=newParse.Query(GameScore);
141
+
query.equalTo('objectId', gameScore.id)
142
+
constsubscription=query.subscribe();
143
+
subscription.on('update', (object) => {
144
+
// Since object (gameScore) is pinned, LDS will update automatically
0 commit comments