GeezerVison is showing github.com — update to local parse and es6 · D-Mbithi/fullstack-javascript@5ad4fe6
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: chapter3/chapter3.md +373-313Lines changed: 373 additions & 313 deletions - Display the source diff
- Display the rich diff
Large diffs are not rendered by default. Collapse file Copy file name to clipboard 127 KB
- Display the source diff
- Display the rich diff
Collapse file Copy file name to clipboard 116 KB
- Display the source diff
- Display the rich diff
Collapse file Copy file name to clipboardExpand all lines: chapter4/chapter4.md +8-8Lines changed: 8 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -59,8 +59,8 @@ including models, subviews, and collections. | 59 | 59 |
| 60 | 60 | Full source code for the Hello World app is available under | 61 | 61 | `05``-backbone/hello-world` and on | 62 | | -[GitHub](https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/hello-world) | 63 | | -(https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/hello-world). | | 62 | +[GitHub](https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/hello-world) | | 63 | +(https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/hello-world). | 64 | 64 |
| 65 | 65 | Backbone.js Dependencies | 66 | 66 | ------------------------ | @@ -236,7 +236,7 @@ demonstrates the project: <http://bit.ly/1O7xRCY>. | 236 | 236 | The full source code of this example is under | 237 | 237 | `05``-backbone/collections`. It's built on top of the "Hello World" | 238 | 238 | example from the Setting up Backbone.js App from Scratch exercise, which | 239 | | -is available for download at [GitHub](https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/collections) (https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/collections). | | 239 | +is available for download at [GitHub](https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/collections) (https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/collections). | 240 | 240 |
| 241 | 241 | We should add some data to play around with, and to hydrate our views. | 242 | 242 | To do this, add this right after the `<script>` tag and before the | @@ -727,7 +727,7 @@ Backbone.js Views and Subviews with Underscore.js | 727 | 727 | Supplemental video which walks you through the implementation and | 728 | 728 | demonstrates the project: <http://bit.ly/1k0ZnUB>. And this example i>s | 729 | 729 | available at | 730 | | -<https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/subview>. | | 730 | +<https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/subview>. | 731 | 731 |
| 732 | 732 | Subviews are Backbone Views that are created and used inside of another | 733 | 733 | Backbone View. A subviews concept is a great way to abstract (separate) | @@ -1353,7 +1353,7 @@ This is the `apple.tpl.js` file: | 1353 | 1353 | </figure>' | 1354 | 1354 |
| 1355 | 1355 | Try to start the application now. The full code is at | 1356 | | -https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/refactor. | | 1356 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/refactor. | 1357 | 1357 |
| 1358 | 1358 |
| 1359 | 1359 |
| @@ -1669,7 +1669,7 @@ the Developers Tool, you can see a difference in how the files are | 1669 | 1669 | loaded. | 1670 | 1670 |
| 1671 | 1671 | The old file shown in Figure 4-2 | 1672 | | -(https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/refactor/index.html) | | 1672 | +(https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/refactor/index.html) | 1673 | 1673 | loads our JavaScript scripts in a serial manner, whereas the new file | 1674 | 1674 | shown in Figure 4-3 | 1675 | 1675 | (https://github.com/azat-co/fullstack-javascript/blob/master/05-backbone/amd/index.html) | @@ -1773,10 +1773,10 @@ For more information, check out the official r.js documentation at | 1773 | 1773 | [`requirejs.org/docs/optimization.html`](http://requirejs.org/docs/optimization.html). | 1774 | 1774 |
| 1775 | 1775 | The example code is available at | 1776 | | -https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/r | | 1776 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/r | 1777 | 1777 |
| 1778 | 1778 | and | 1779 | | -https://github.com/azat-co/fullstack-javascript/tree/master/05-backbone/r/build. | | 1779 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/05-backbone/r/build. | 1780 | 1780 |
| 1781 | 1781 | For uglification of JS files (which decreases the file sizes), we can | 1782 | 1782 | use the [Uglify2](https://github.com/mishoo/UglifyJS2) module. To | |
Collapse file Copy file name to clipboardExpand all lines: chapter5/chapter5.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -49,7 +49,7 @@ implementation of user actions by binding them to asynchronous updates | 49 | 49 | of the collection. | 50 | 50 |
| 51 | 51 | The application is available at | 52 | | -<https://github.com/azat-co/fullstack-javascript/tree/master/06-board-backbone-parse-sdk>, | | 52 | +<https://github.com/azat-co/fullstack-javascript/tree/master/code/06-board-backbone-parse-sdk>, | 53 | 53 | but again you are encouraged to start from scratch and try to write your | 54 | 54 | own code using the example only as a reference. | 55 | 55 |
| @@ -634,7 +634,7 @@ something like this: | 634 | 634 |
| 635 | 635 | The full source code of the Backbone.js and Parse.com Message Board | 636 | 636 | application is available at | 637 | | -<https://github.com/azat-co/fullstack-javascript/tree/master/06-board-backbone-parse-sdk>. | | 637 | +<https://github.com/azat-co/fullstack-javascript/tree/master/code/06-board-backbone-parse-sdk>. | 638 | 638 |
| 639 | 639 | Taking Message Board Further | 640 | 640 | ============================ | |
Collapse file Copy file name to clipboardExpand all lines: chapter6/chapter6.md +4-4Lines changed: 4 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -55,7 +55,7 @@ between Node.js versions): | 55 | 55 | - [nvm](https://github.com/creationix/nvm) (<https://github.com/creationix/nvm>) | 56 | 56 |
| 57 | 57 | As usual, you could copy example code at | 58 | | -https://github.com/azat-co/fullstack-javascript/tree/master/07-hello, or | | 58 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/07-hello, or | 59 | 59 | write your own program from scratch. If you wish to do the latter, | 60 | 60 | create a folder `hello` for your "Hello World" Node.js application. Then | 61 | 61 | create file a `server.js` and line by line type the code below. | @@ -359,7 +359,7 @@ Deploying to Heroku | 359 | 359 |
| 360 | 360 | For Heroku deployment, we need to create two extra files: `Procfile` and | 361 | 361 | `package.json`. You could get the source code from | 362 | | -https://github.com/azat-co/fullstack-javascript/tree/master/07-hello or | | 362 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/07-hello or | 363 | 363 | write your own one. | 364 | 364 |
| 365 | 365 | The structure of the "Hello World" application looks like this: | @@ -417,7 +417,7 @@ time we start/reset the server, the data will be lost. | 417 | 417 |
| 418 | 418 | We'll start with a simple test case first to illustrate the Test-Driven | 419 | 419 | Development approach. The full code is available at | 420 | | -https://github.com/azat-co/fullstack-javascript/tree/master/08-test. | | 420 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/08-test. | 421 | 421 |
| 422 | 422 | Unit Testing Node.js | 423 | 423 | -------------------- | @@ -677,7 +677,7 @@ Also returning a new message in a JSON-as-a-string format: | 677 | 677 |
| 678 | 678 | Here is the full code of `mb-server.js` minus the comments. It's | 679 | 679 | also available at | 680 | | -[08-test](https://github.com/azat-co/fullstack-javascript/tree/master/08-test): | | 680 | +[08-test](https://github.com/azat-co/fullstack-javascript/tree/master/code/08-test): | 681 | 681 |
| 682 | 682 | var http = require('http') | 683 | 683 | // Loads http module | |
Collapse file Copy file name to clipboardExpand all lines: chapter7/chapter7.md +4-4Lines changed: 4 additions & 4 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -321,7 +321,7 @@ var dbConnUrl = process.env.MONGOLAB_URI || | 321 | 321 | ``` | 322 | 322 |
| 323 | 323 | Here is our updated cross-environment ready `app.js` file | 324 | | -(https://github.com/azat-co/fullstack-javascript/tree/master/10-db-connect-heroku). | | 324 | +(https://github.com/azat-co/fullstack-javascript/tree/master/code/10-db-connect-heroku). | 325 | 325 | I added a method to get the list of collections `listCollections` | 326 | 326 | instead of getting the list of the databases (we have only one database | 327 | 327 | in MongoLab right now): | @@ -381,7 +381,7 @@ Heroku app, if you know the name of that app. | 381 | 381 |
| 382 | 382 | The project folder needs to have `Procfile` and `package.json`. You can | 383 | 383 | copy them from | 384 | | -https://github.com/azat-co/fullstack-javascript/tree/master/10-db-connect-heroku. | | 384 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/10-db-connect-heroku. | 385 | 385 |
| 386 | 386 | Now you can push you code to Heroku with: | 387 | 387 |
| @@ -440,7 +440,7 @@ client.connect(dbConnUrl, {}, function(error, db) { | 440 | 440 | ``` | 441 | 441 |
| 442 | 442 | The final Heroku-deployment-ready project is located at | 443 | | -https://github.com/azat-co/fullstack-javascript/tree/master/11-db-serverunder. | | 443 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/11-db-serverunder. | 444 | 444 |
| 445 | 445 | After the deployment you should be able to open the URL provided by | 446 | 446 | Heroku and see the list of collections. If it's a newly created app with | @@ -460,7 +460,7 @@ http://bit.ly/1QnsfoE. | 460 | 460 | We should have everything set up for writing the Node.js application | 461 | 461 | that will work both locally and on Heroku. The source code is available | 462 | 462 | at | 463 | | -https://github.com/azat-co/fullstack-javascript/tree/master/12-board-api-mongonder. | | 463 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/12-board-api-mongonder. | 464 | 464 | The structure of the application is simple: | 465 | 465 |
| 466 | 466 | ``` | |
Collapse file Copy file name to clipboardExpand all lines: chapter8/chapter8.md +5-5Lines changed: 5 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| 353 | 353 | }) | 354 | 354 |
| 355 | 355 | This is it. For your reference, the front-end app source code is at | 356 | | -[https://github.com/azat-co/fullstack-javascript/tree/master/13-board-u](https://github.com/azat-co/fullstack-javascript/tree/master/13-board-ui) | | 356 | +[https://github.com/azat-co/fullstack-javascript/tree/master/code/13-board-u](https://github.com/azat-co/fullstack-javascript/tree/master/code/13-board-ui) | 357 | 357 | in the GitHub folder. I won't list it here because we had only a few | 358 | 358 | changes comparing with the Parse SDK project. The next piece of the | 359 | 359 | puzzle is the back end. | @@ -366,7 +366,7 @@ through the implementation and demonstrates the project: | 366 | 366 | http://bit.ly/1QnsvEb. | 367 | 367 |
| 368 | 368 | The back-end Node.js application source code is at | 369 | | -<https://github.com/azat-co/fullstack-javascript/tree/master/14-board-api> | | 369 | +<https://github.com/azat-co/fullstack-javascript/tree/master/code/14-board-api> | 370 | 370 | in the GitHub folder, which has this structure: | 371 | 371 |
| 372 | 372 | /14-board-api | @@ -558,9 +558,9 @@ you through the implementation and demonstrates the project: | 558 | 558 | http://bit.ly/1QnsvEb. | 559 | 559 |
| 560 | 560 | For your convenience, we have the front-end app at | 561 | | -https://github.com/azat-co/fullstack-javascript/tree/master/13-board-ui | | 561 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/13-board-ui | 562 | 562 | and the back-end app with CORS is located at | 563 | | -https://github.com/azat-co/fullstack-javascript/tree/master/14-board-api. | | 563 | +https://github.com/azat-co/fullstack-javascript/tree/master/code/14-board-api. | 564 | 564 | By now, you probably know what to do, but as a reference, below are the | 565 | 565 | steps to deploy these examples to Heroku. | 566 | 566 |
| @@ -731,7 +731,7 @@ Another header that we send back with the response is `Content-Length`: | 731 | 731 | So this piece of code goes into the request handler of the server, which | 732 | 732 | is inside of the database connect call. Just like the Russian Matreshka | 733 | 733 | dolls. Confusing? Just refer to the full source code at | 734 | | -<https://github.com/azat-co/fullstack-javascript/tree/master/15-board-web>. | | 734 | +<https://github.com/azat-co/fullstack-javascript/tree/master/code/15-board-web>. | 735 | 735 |
| 736 | 736 | Another, more elegant way is to use Node.js frameworks as Connect | 737 | 737 | (<http://www.senchalabs.org/connect/static.html>), or Express | |
Collapse file Copy file name to clipboard +60-63Lines changed: 60 additions & 63 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// const parseAppID = 'your-parse-app-id' | 2 | | -// const parseRestKey = 'your-rest-api-key' | 3 | | - | 4 | 1 | // Azat's app, change these values to your own keys | 5 | 2 | const parseAppID = 'APPLICATION_ID' | 6 | 3 | const parseRestKey = 'MASTER_KEY' | 7 | 4 | const apiBase = `http://localhost:1337/parse` | 8 | 5 |
| 9 | 6 | $(document).ready(function(){ | 10 | | - getMessages() | 11 | | - $('#send').click(function(){ | 12 | | - const $sendButton = $(this) | 13 | | - $sendButton.html('<img src="img/spinner.gif" width="20"/>') | 14 | | - const username = $('input[name=username]').val() | 15 | | - const message = $('input[name=message]').val() | 16 | | - $.ajax({ | 17 | | - url: `${apiBase}/classes/MessageBoard`, | 18 | | - headers: { | 19 | | - 'X-Parse-Application-Id': parseAppID, | 20 | | - 'X-Parse-REST-API-Key': parseRestKey | 21 | | - }, | 22 | | - contentType: 'application/json', | 23 | | - dataType: 'json', | 24 | | - processData: false, | 25 | | - data: JSON.stringify({ | 26 | | - 'username': username, | 27 | | - 'message': message | 28 | | - }), | 29 | | - type: 'POST', | 30 | | - success: function() { | 31 | | - console.log('sent') | 32 | | - getMessages() | 33 | | - $sendButton.html('SEND') | 34 | | - }, | 35 | | - error: function() { | 36 | | - console.log('error') | 37 | | - $sendButton.html('SEND') | 38 | | - } | 39 | | - }) | 40 | | - }) | | 7 | + getMessages() | | 8 | + $('#send').click(function(){ | | 9 | + const $sendButton = $(this) | | 10 | + $sendButton.html('<img src="img/spinner.gif" width="20"/>') | | 11 | + const username = $('input[name=username]').val() | | 12 | + const message = $('input[name=message]').val() | | 13 | + $.ajax({ | | 14 | + url: `${apiBase}/classes/MessageBoard`, | | 15 | + headers: { | | 16 | + 'X-Parse-Application-Id': parseAppID, | | 17 | + 'X-Parse-REST-API-Key': parseRestKey | | 18 | + }, | | 19 | + contentType: 'application/json', | | 20 | + dataType: 'json', | | 21 | + processData: false, | | 22 | + data: JSON.stringify({ | | 23 | + 'username': username, | | 24 | + 'message': message | | 25 | + }), | | 26 | + type: 'POST', | | 27 | + success: function() { | | 28 | + console.log('sent') | | 29 | + getMessages() | | 30 | + $sendButton.html('SEND') | | 31 | + }, | | 32 | + error: function() { | | 33 | + console.log('error') | | 34 | + $sendButton.html('SEND') | | 35 | + } | | 36 | + }) | | 37 | + }) | 41 | 38 | }) | 42 | 39 |
| 43 | 40 | function getMessages() { | 44 | | - $.ajax({ | 45 | | - url: `${apiBase}/classes/MessageBoard?limit=1000`, | 46 | | - headers: { | 47 | | - 'X-Parse-Application-Id': parseAppID, | 48 | | - 'X-Parse-REST-API-Key': parseRestKey | 49 | | - }, | 50 | | - contentType: 'application/json', | 51 | | - dataType: 'json', | 52 | | - type: 'GET', | 53 | | - success: (data) => { | 54 | | - console.log('get') | 55 | | - updateView(data) | 56 | | - }, | 57 | | - error: () => { | 58 | | - console.log('error') | 59 | | - } | 60 | | - }) | | 41 | + $.ajax({ | | 42 | + url: `${apiBase}/classes/MessageBoard?limit=1000`, | | 43 | + headers: { | | 44 | + 'X-Parse-Application-Id': parseAppID, | | 45 | + 'X-Parse-REST-API-Key': parseRestKey | | 46 | + }, | | 47 | + contentType: 'application/json', | | 48 | + dataType: 'json', | | 49 | + type: 'GET', | | 50 | + success: (data) => { | | 51 | + console.log('get') | | 52 | + updateView(data) | | 53 | + }, | | 54 | + error: () => { | | 55 | + console.log('error') | | 56 | + } | | 57 | + }) | 61 | 58 | } | 62 | 59 |
| 63 | 60 | function updateView(messages) { | 64 | | - // messages.results = messages.results.reverse() | 65 | | - const table = $('.table tbody') | 66 | | - table.html('') | 67 | | - $.each(messages.results, (index, value) => { | 68 | | - const trEl = (`<tr><td> | 69 | | - ${value.username} | 70 | | - </td><td> | 71 | | - ${value.message} | 72 | | - </td></tr>`) | 73 | | - table.append(trEl) | 74 | | - }) | 75 | | - console.log(messages) | | 61 | + // messages.results = messages.results.reverse() | | 62 | + const table = $('.table tbody') | | 63 | + table.html('') | | 64 | + $.each(messages.results, (index, value) => { | | 65 | + const trEl = (`<tr><td> | | 66 | + ${value.username} | | 67 | + </td><td> | | 68 | + ${value.message} | | 69 | + </td></tr>`) | | 70 | + table.append(trEl) | | 71 | + }) | | 72 | + console.log(messages) | 76 | 73 | } |
Collapse file Copy file name to clipboardExpand all lines: code/03-parse-sdk/app.js +13-13Lines changed: 13 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -4,29 +4,28 @@ $(document).ready(function() { | 4 | 4 | const parseApplicationId = 'APPLICATION_ID' | 5 | 5 | const parseJavaScriptKey = 'MASTER_KEY' | 6 | 6 |
| 7 | | - //change parseApplicationId and parseJavaScriptKey to values from Parse.com application dashboard | 8 | 7 | Parse.initialize(parseApplicationId, parseJavaScriptKey) | 9 | 8 | Parse.serverURL = 'http://localhost:1337/parse' | 10 | 9 |
| 11 | | - var Test = Parse.Object.extend('Test') | 12 | | - var test = new Test() | 13 | | - var query = new Parse.Query(Test); | | 10 | + const Test = Parse.Object.extend('Test') | | 11 | + const test = new Test() | | 12 | + const query = new Parse.Query(Test) | 14 | 13 |
| 15 | 14 | $('.btn-save').click(function(){ | 16 | 15 | try { | 17 | | - var data = JSON.parse($('textarea').val()) | | 16 | + const data = JSON.parse($('textarea').val()) | 18 | 17 | } catch (e) { | 19 | 18 | alert('Invalid JSON') | 20 | 19 | } | 21 | 20 | if (!data) return false | 22 | 21 | test.save(data, { | 23 | | - success: function(object) { | 24 | | - console.log('Parse.com object is saved: ', object) | 25 | | - $('.log').html(JSON.stringify(object, null, 2)) | 26 | | - //alternatively you could use alert('Parse.com object is saved') | | 22 | + success: (result) => { | | 23 | + console.log('Parse.com object is saved: ', result) | | 24 | + $('.log').html(JSON.stringify(result, null, 2)) | | 25 | + //alternatively you could use alert('Parse object is saved') | 27 | 26 | }, | 28 | | - error: function(object) { | 29 | | - console.log('Error! Parse.com object is not saved: ', object) | | 27 | + error: (error) => { | | 28 | + console.log(`Error! Parse.com object is not saved: ${error}`) | 30 | 29 | } | 31 | 30 | }) | 32 | 31 | }) | @@ -37,8 +36,9 @@ $(document).ready(function() { | 37 | 36 | $('.log').html(JSON.stringify(results, null, 2)) | 38 | 37 | }, | 39 | 38 | error: function(error) { | 40 | | - alert("Error: " + error.code + " " + error.message); | | 39 | + alert(`Error: ${error.code} ${error.message}`) | 41 | 40 | } | 42 | | - }); | | 41 | + }) | 43 | 42 | }) | | 43 | + | 44 | 44 | }) |
|