Skip to content

Commit

Permalink
docs: Add JS doc for Parse.Object.revert() (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicksonYap authored Jul 1, 2024
1 parent e0a4901 commit 254bb8d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2,975 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run husky-pre-commit
28 changes: 28 additions & 0 deletions _includes/js/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,34 @@ query.distinct("age")
});
```

## Local vs. Server Data

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.

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.

If this is not a desired behavior, use `.revert()` to clear and unsaved local changes applied to the object.

```javascript
// Save object
const GameScore = Parse.Object.extend("GameScore");
const localObject = new Parse.Object(GameScore);
localObject.set('field', 'a');
await localObject.save();

// Modify object locally without saving it
localObject.set('field', 'b');

// Fetch local object from server
const query = new Parse.Query(GameScore);
const fetchedObject = await query.first();

// Determine field value
fetchedObject.get('field'); // Returns value 'b'
fetchedObject.revert();
fetchedObject.get('field'); // Returns value 'a'
```

## Read Preference

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.
Expand Down
2,961 changes: 2 additions & 2,959 deletions assets/js/bundle.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dev": "npm run dev-webpack & npm run jekyll",
"dev-win": "start npm run dev-webpack & start npm run jekyll",
"prod": "npm run webpack & npm run jekyll",
"test": "echo \"Error: no test specified\" && exit 1"
"husky-pre-commit": "npm run webpack && git add assets/js/bundle.js"
},
"repository": {
"type": "git",
Expand All @@ -29,17 +29,12 @@
"babel-loader": "8.3.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-react": "6.24.1",
"husky": "8.0.3",
"husky": "9.0.11",
"webpack": "5.76.0",
"webpack-cli": "4.1.0"
},
"dependencies": {
"jquery": "3.5.1",
"underscore": "1.12.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run webpack && git add assets/js/bundle.js"
}
}
}

0 comments on commit 254bb8d

Please sign in to comment.