Skip to content

Commit

Permalink
Replace var to const (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
davimacedo authored Nov 18, 2020
1 parent 6e2a85a commit 52e01b1
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 159 deletions.
4 changes: 2 additions & 2 deletions _includes/js/analytics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Without having to implement any client-side logic, you can view real-time graphs
Say your app offers search functionality for apartment listings, and you want to track how often the feature is used, with some additional metadata.

```javascript
var dimensions = {
const dimensions = {
// Define ranges to bucket data points into meaningful segments
priceRange: '1000-1500',
// Did the user filter the query?
Expand All @@ -29,7 +29,7 @@ Parse.Analytics.track('search', dimensions);
`Parse.Analytics` can even be used as a lightweight error tracker — simply invoke the following and you'll have access to an overview of the rate and frequency of errors, broken down by error code, in your application:

```javascript
var codeString = '' + error.code;
const codeString = '' + error.code;
Parse.Analytics.track('error', { code: codeString });
```

Expand Down
22 changes: 11 additions & 11 deletions _includes/js/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
Getting started with `Parse.File` is easy. There are a couple of ways to create a file. The first is with a base64-encoded String.

```javascript
var base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
var file = new Parse.File("myfile.txt", { base64: base64 });
const base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
const file = new Parse.File("myfile.txt", { base64: base64 });
```

Alternatively, you can create a file from an array of byte values:

```javascript
var bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
var file = new Parse.File("myfile.txt", bytes);
const bytes = [ 0xBE, 0xEF, 0xCA, 0xFE ];
const file = new Parse.File("myfile.txt", bytes);
```

Parse will auto-detect the type of file you are uploading based on the file extension, but you can specify the `Content-Type` with a third parameter:

```javascript
var file = new Parse.File("myfile.zzz", fileData, "image/png");
const file = new Parse.File("myfile.zzz", fileData, "image/png");
```

### Client Side
Expand All @@ -34,12 +34,12 @@ In a browser, you'll want to use an html form with a file upload control. To do
Then, in a click handler or other function, get a reference to that file:

```javascript
var fileUploadControl = $("#profilePhotoFileUpload")[0];
const fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
var file = fileUploadControl.files[0];
var name = "photo.jpg";
const file = fileUploadControl.files[0];
const name = "photo.jpg";

var parseFile = new Parse.File(name, file);
const parseFile = new Parse.File(name, file);
}
```

Expand Down Expand Up @@ -88,7 +88,7 @@ request(options)
Finally, after the save completes, you can associate a `Parse.File` with a `Parse.Object` just like any other piece of data:

```javascript
var jobApplication = new Parse.Object("JobApplication");
const jobApplication = new Parse.Object("JobApplication");
jobApplication.set("applicantName", "Joe Smith");
jobApplication.set("applicantResumeFile", parseFile);
jobApplication.save();
Expand All @@ -99,7 +99,7 @@ jobApplication.save();
How to best retrieve the file contents back depends on the context of your application. Because of cross-domain request issues, it's best if you can make the browser do the work for you. Typically, that means rendering the file's URL into the DOM. Here we render an uploaded profile photo on a page with jQuery:

```javascript
var profilePhoto = profile.get("photoFile");
const profilePhoto = profile.get("photoFile");
$("profileImg")[0].src = profilePhoto.url();
```

Expand Down
8 changes: 4 additions & 4 deletions _includes/js/geopoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Parse allows you to associate real-world latitude and longitude coordinates with
To associate a point with an object you first need to create a `Parse.GeoPoint`. For example, to create a point with latitude of 40.0 degrees and -30.0 degrees longitude:

```javascript
var point = new Parse.GeoPoint({latitude: 40.0, longitude: -30.0});
const point = new Parse.GeoPoint({latitude: 40.0, longitude: -30.0});
```

This point is then stored in the object as a regular field.
Expand Down Expand Up @@ -67,10 +67,10 @@ const pizzaPlacesInSF = query.find();
It's also possible to query for the set of objects that are contained within a particular area. To find the objects in a rectangular bounding box, add the `withinGeoBox` restriction to your `Parse.Query`.

```javascript
var southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
var northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962);
const southwestOfSF = new Parse.GeoPoint(37.708813, -122.526398);
const northeastOfSF = new Parse.GeoPoint(37.822802, -122.373962);

var query = new Parse.Query(PizzaPlaceObject);
const query = new Parse.Query(PizzaPlaceObject);
query.withinGeoBox("location", southwestOfSF, northeastOfSF);
const pizzaPlacesInSF = await query.find();
```
Expand Down
6 changes: 3 additions & 3 deletions _includes/js/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ The JavaScript ecosystem is wide and incorporates a large number of platforms an
To use the npm modules for a browser based application, include it as you normally would:

```js
var Parse = require('parse');
const Parse = require('parse');
```

For server-side applications or Node.js command line tools, include `'parse/node'`:

```js
// In a node.js environment
var Parse = require('parse/node');
const Parse = require('parse/node');
// ES6 Minimized
import Parse from 'parse/dist/parse.min.js';
```

For React Native applications, include `'parse/react-native.js'`:
```js
// In a React Native application
var Parse = require('parse/react-native.js');
const Parse = require('parse/react-native.js');
```

Additionally on React-Native / Expo environments, make sure to add the piece of code below :
Expand Down
102 changes: 51 additions & 51 deletions _includes/js/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ To create a new subclass, use the `Parse.Object.extend` method. Any `Parse.Quer

```javascript
// Simple syntax to create a new subclass of Parse.Object.
var GameScore = Parse.Object.extend("GameScore");
const GameScore = Parse.Object.extend("GameScore");

// Create a new instance of that class.
var gameScore = new GameScore();
const gameScore = new GameScore();

// Alternatively, you can use the typical Backbone syntax.
var Achievement = Parse.Object.extend({
const Achievement = Parse.Object.extend({
className: "Achievement"
});
```
Expand All @@ -34,7 +34,7 @@ You can add additional methods and properties to your subclasses of `Parse.Objec
```javascript

// A complex subclass of Parse.Object
var Monster = Parse.Object.extend("Monster", {
const Monster = Parse.Object.extend("Monster", {
// Instance methods
hasSuperHumanStrength: function () {
return this.get("strength") > 18;
Expand All @@ -46,13 +46,13 @@ var Monster = Parse.Object.extend("Monster", {
}, {
// Class methods
spawn: function(strength) {
var monster = new Monster();
const monster = new Monster();
monster.set("strength", strength);
return monster;
}
});

var monster = Monster.spawn(200);
const monster = Monster.spawn(200);
alert(monster.get('strength')); // Displays 200.
alert(monster.sound); // Displays Rawr.
```
Expand All @@ -75,7 +75,7 @@ class Monster extends Parse.Object {
}

static spawn(strength) {
var monster = new Monster();
const monster = new Monster();
monster.set('strength', strength);
return monster;
}
Expand Down Expand Up @@ -156,8 +156,8 @@ There are also a few fields you don't need to specify that are provided as a con
If you prefer, you can set attributes directly in your call to `save` instead.

```javascript
var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
const GameScore = Parse.Object.extend("GameScore");
const gameScore = new GameScore();

gameScore.save({
score: 1337,
Expand All @@ -176,22 +176,22 @@ gameScore.save({
You may add a `Parse.Object` as the value of a property in another `Parse.Object`. By default, when you call `save()` on the parent object, all nested objects will be created and/or saved as well in a batch operation. This feature makes it really easy to manage relational data as you don't have to take care of creating the objects in any specific order.

```javascript
var Child = Parse.Object.extend("Child");
var child = new Child();
const Child = Parse.Object.extend("Child");
const child = new Child();

var Parent = Parse.Object.extend("Parent");
var parent = new Parent();
const Parent = Parse.Object.extend("Parent");
const parent = new Parent();

parent.save({child: child});
parent.save({ child: child });
// Automatically the object Child is created on the server
// just before saving the Parent
```

In some scenarios, you may want to prevent this default chain save. For example, when saving a team member's profile that points to an account owned by another user to which you don't have write access. In this case, setting the option `cascadeSave` to `false` may be useful:

```javascript
var TeamMember = Parse.Object.extend("TeamMember");
var teamMember = new TeamMember();
const TeamMember = Parse.Object.extend("TeamMember");
const teamMember = new TeamMember();
teamMember.set('ownerAccount', ownerAccount); // Suppose `ownerAccount` has been created earlier.

teamMember.save(null, { cascadeSave: false });
Expand All @@ -206,22 +206,22 @@ teamMember.save(null, { cascadeSave: false });
You may pass a `context` dictionary that is accessible in Cloud Code `beforeSave` and `afterSave` triggers for that `Parse.Object`. This is useful if you want to condition certain operations in Cloud Code triggers on ephemeral information that should not be saved with the `Parse.Object` in the database. The context is ephemeral in the sense that it vanishes after the Cloud Code triggers for that particular `Parse.Object` have executed. For example:

```javascript
var TeamMember = Parse.Object.extend("TeamMember");
var teamMember = new TeamMember();
const TeamMember = Parse.Object.extend("TeamMember");
const teamMember = new TeamMember();
teamMember.set("team", "A");

var context = { notifyTeam: false };
const context = { notifyTeam: false };
await teamMember.save(null, { context: context });
```

The context is then accessible in Cloud Code:

```javascript
Parse.Cloud.afterSave("TeamMember", async (req) => {
var notifyTeam = req.context.notifyTeam;
if (notifyTeam) {
// Notify team about new member.
}
const notifyTeam = req.context.notifyTeam;
if (notifyTeam) {
// Notify team about new member.
}
});
```

Expand All @@ -230,8 +230,8 @@ Parse.Cloud.afterSave("TeamMember", async (req) => {
Saving data to the cloud is fun, but it's even more fun to get that data out again. If the `Parse.Object` has been uploaded to the server, you can use the `objectId` to get it using a `Parse.Query`:

```javascript
var GameScore = Parse.Object.extend("GameScore");
var query = new Parse.Query(GameScore);
const GameScore = Parse.Object.extend("GameScore");
const query = new Parse.Query(GameScore);
query.get("xWMyZ4YEGZ")
.then((gameScore) => {
// The object was retrieved successfully.
Expand All @@ -244,9 +244,9 @@ query.get("xWMyZ4YEGZ")
To get the values out of the `Parse.Object`, use the `get` method.

```javascript
var score = gameScore.get("score");
var playerName = gameScore.get("playerName");
var cheatMode = gameScore.get("cheatMode");
const score = gameScore.get("score");
const playerName = gameScore.get("playerName");
const cheatMode = gameScore.get("cheatMode");
```

Alternatively, the `attributes` property of the `Parse.Object` can be treated as a Javascript object, and even destructured.
Expand All @@ -258,10 +258,10 @@ const { score, playerName, cheatMode } = result.attributes;
The four special reserved values are provided as properties and cannot be retrieved using the 'get' method nor modified with the 'set' method:

```javascript
var objectId = gameScore.id;
var updatedAt = gameScore.updatedAt;
var createdAt = gameScore.createdAt;
var acl = gameScore.getACL();
const objectId = gameScore.id;
const updatedAt = gameScore.updatedAt;
const createdAt = gameScore.createdAt;
const acl = gameScore.getACL();
```

If you need to refresh an object you already have with the latest data that
Expand Down Expand Up @@ -290,8 +290,8 @@ Updating an object is simple. Just set some new data on it and call the save met

```javascript
// Create the object.
var GameScore = Parse.Object.extend("GameScore");
var gameScore = new GameScore();
const GameScore = Parse.Object.extend("GameScore");
const gameScore = new GameScore();

gameScore.set("score", 1337);
gameScore.set("playerName", "Sean Plott");
Expand Down Expand Up @@ -378,16 +378,16 @@ To create a new `Post` with a single `Comment`, you could write:

```javascript
// Declare the types.
var Post = Parse.Object.extend("Post");
var Comment = Parse.Object.extend("Comment");
const Post = Parse.Object.extend("Post");
const Comment = Parse.Object.extend("Comment");

// Create the post
var myPost = new Post();
const myPost = new Post();
myPost.set("title", "I'm Hungry");
myPost.set("content", "Where should we go for lunch?");

// Create the comment
var myComment = new Comment();
const myComment = new Comment();
myComment.set("content", "Let's do Sushirrito.");

// Add the post as a value in the comment
Expand All @@ -400,7 +400,7 @@ myComment.save();
Internally, the Parse framework will store the referred-to object in just one place, to maintain consistency. You can also link objects using just their `objectId`s like so:

```javascript
var post = new Post();
const post = new Post();
post.id = "1zEcyElZ80";

myComment.set("parent", post);
Expand All @@ -419,8 +419,8 @@ const title = post.get("title");
Many-to-many relationships are modeled using `Parse.Relation`. This works similar to storing an array of `Parse.Object`s in a key, except that you don't need to fetch all of the objects in a relation at once. In addition, this allows `Parse.Relation` to scale to many more objects than the array of `Parse.Object` approach. For example, a `User` may have many `Posts` that she might like. In this case, you can store the set of `Posts` that a `User` likes using `relation`. In order to add a `Post` to the "likes" list of the `User`, you can do:

```javascript
var user = Parse.User.current();
var relation = user.relation("likes");
const user = Parse.User.current();
const relation = user.relation("likes");
relation.add(post);
user.save();
```
Expand Down Expand Up @@ -460,7 +460,7 @@ relation.query().find({
If you want only a subset of the Posts, you can add extra constraints to the `Parse.Query` returned by query like this:

```javascript
var query = relation.query();
const query = relation.query();
query.equalTo("title", "I'm Hungry");
query.find({
success:function(list) {
Expand Down Expand Up @@ -489,16 +489,16 @@ So far we've used values with type `String`, `Number`, and `Parse.Object`. Parse
Some examples:

```javascript
var number = 42;
var bool = false;
var string = "the number is " + number;
var date = new Date();
var array = [string, number];
var object = { number: number, string: string };
var pointer = MyClassName.createWithoutData(objectId);
const number = 42;
const bool = false;
const string = "the number is " + number;
const date = new Date();
const array = [string, number];
const object = { number: number, string: string };
const pointer = MyClassName.createWithoutData(objectId);

var BigObject = Parse.Object.extend("BigObject");
var bigObject = new BigObject();
const BigObject = Parse.Object.extend("BigObject");
const bigObject = new BigObject();
bigObject.set("myNumber", number);
bigObject.set("myBool", bool);
bigObject.set("myString", string);
Expand Down
Loading

0 comments on commit 52e01b1

Please sign in to comment.