Skip to content

Commit 49aa99a

Browse files
committed
add livequery description
1 parent ccbf622 commit 49aa99a

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

_includes/js/local-datastore.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const result = await query.get('xWMyZ4YE');
3535

3636
## Querying the Local Datastore
3737

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.
3939

4040
```javascript
4141
const GameScore = Parse.Object.extend("GameScore");
@@ -67,7 +67,7 @@ await Parse.Object.unPinAllObjects();
6767

6868
## Pinning with Labels
6969

70-
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.
7171

7272
```javascript
7373
// Add several objects with a label.
@@ -89,7 +89,7 @@ There's also a method to remove all objects from a label.
8989
await Parse.Object.unPinAllObjectsWithName('MyScores');
9090
```
9191

92-
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 labels will stay in the datastore if one of the two labels is unpinned.
9393

9494
## Caching Query Results
9595

@@ -128,3 +128,19 @@ The local datastore is a dictionary of key / values. Each object has a key (clas
128128
`pinWithName('YourPinName')` will save this reference under `parsePin_YourPinName`
129129

130130
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+
const gameScore = new GameScore();
138+
await gameScore.save();
139+
await gameScore.pin();
140+
const query = new Parse.Query(GameScore);
141+
query.equalTo('objectId', gameScore.id)
142+
const subscription = query.subscribe();
143+
subscription.on('update', (object) => {
144+
// Since object (gameScore) is pinned, LDS will update automatically
145+
});
146+
```

assets/js/bundle.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)