Skip to content

Commit 254bb8d

Browse files
authored
docs: Add JS doc for Parse.Object.revert() (#555)
1 parent e0a4901 commit 254bb8d

File tree

5 files changed

+45
-2975
lines changed

5 files changed

+45
-2975
lines changed

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run husky-pre-commit

_includes/js/queries.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,34 @@ query.distinct("age")
570570
});
571571
```
572572

573+
## Local vs. Server Data
574+
575+
The value of a Parse Object field is determined from two data sources: the last-known value sent by the server, and any local changes made via `.set()` that have not been saved and sent to the server yet. When calling `.get()` on a field, the returned value will be the unsaved local value, or if no change has been made, the last-known value sent by the server.
576+
577+
If you called `.set()` on a field but did not save it, then calling `.get()` will always return the unsaved value, regardless of how the value changed on the server side.
578+
579+
If this is not a desired behavior, use `.revert()` to clear and unsaved local changes applied to the object.
580+
581+
```javascript
582+
// Save object
583+
const GameScore = Parse.Object.extend("GameScore");
584+
const localObject = new Parse.Object(GameScore);
585+
localObject.set('field', 'a');
586+
await localObject.save();
587+
588+
// Modify object locally without saving it
589+
localObject.set('field', 'b');
590+
591+
// Fetch local object from server
592+
const query = new Parse.Query(GameScore);
593+
const fetchedObject = await query.first();
594+
595+
// Determine field value
596+
fetchedObject.get('field'); // Returns value 'b'
597+
fetchedObject.revert();
598+
fetchedObject.get('field'); // Returns value 'a'
599+
```
600+
573601
## Read Preference
574602

575603
When using a MongoDB replica set, you can use the `query.readPreference(readPreference, includeReadPreference, subqueryReadPreference)` function to choose from which replica the objects will be retrieved. The `includeReadPreference` argument chooses from which replica the included pointers will be retrieved and the `subqueryReadPreference` argument chooses in which replica the subqueries will run. The possible values are `PRIMARY` (default), `PRIMARY_PREFERRED`, `SECONDARY`, `SECONDARY_PREFERRED`, or `NEAREST`. If the `includeReadPreference` argument is not passed, the same replica chosen for `readPreference` will be also used for the includes. The same rule applies for the `subqueryReadPreference` argument.

assets/js/bundle.js

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

package-lock.json

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

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dev": "npm run dev-webpack & npm run jekyll",
1212
"dev-win": "start npm run dev-webpack & start npm run jekyll",
1313
"prod": "npm run webpack & npm run jekyll",
14-
"test": "echo \"Error: no test specified\" && exit 1"
14+
"husky-pre-commit": "npm run webpack && git add assets/js/bundle.js"
1515
},
1616
"repository": {
1717
"type": "git",
@@ -29,17 +29,12 @@
2929
"babel-loader": "8.3.0",
3030
"babel-preset-es2015": "6.24.1",
3131
"babel-preset-react": "6.24.1",
32-
"husky": "8.0.3",
32+
"husky": "9.0.11",
3333
"webpack": "5.76.0",
3434
"webpack-cli": "4.1.0"
3535
},
3636
"dependencies": {
3737
"jquery": "3.5.1",
3838
"underscore": "1.12.1"
39-
},
40-
"husky": {
41-
"hooks": {
42-
"pre-commit": "npm run webpack && git add assets/js/bundle.js"
43-
}
4439
}
4540
}

0 commit comments

Comments
 (0)