Skip to content

Commit f947f25

Browse files
committed
Finishing a second pass through section 5.0
1 parent 785a364 commit f947f25

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

images/chapter5/android/1.png

181 KB
Loading

images/chapter5/android/2.gif

-50.1 KB
Binary file not shown.

images/chapter5/ios/1.png

244 KB
Loading

images/chapter5/ios/2.gif

-518 KB
Binary file not shown.

index.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ <h4 class="exercise-start">
661661
<b>Exercise</b>: Add a model object
662662
</h4>
663663

664-
<p>Let’s start by creating a simple model object to store user data. Open <code>app/user/user.ts</code> and paste in the following code:</p>
664+
<p>Let’s start by creating a simple model object to store user data. Open <code>app/shared/user/user.ts</code> and paste in the following code:</p>
665665
<pre><code class="lang-JavaScript">export class User {
666666
email: string;
667667
password: string;
@@ -1580,8 +1580,25 @@ <h4 class="exercise-start">
15801580
</code></pre>
15811581
<div class="exercise-end"></div>
15821582

1583-
<p>Explain this code.</p>
1584-
<p>TODO: Add images</p>
1583+
<p>Now, if the user attempts to login or register with an invalid email address, they’ll see an alert that points out the error. However in order to test out this change you’ll need to do one more thing.</p>
1584+
<h4 class="exercise-start">
1585+
<b>Exercise</b>: Rebuild your app
1586+
</h4>
1587+
1588+
<p>As we mentioned in chapter 1.4, although the <code>tns livesync</code> command is smart enough to reload your app for most changes you make to your app, the command cannot hot reload your app for all changes—most notably, changes to native files in <code>app/App_Resources</code>, new modules installed with <code>npm install</code>, and new NativeScript plugins.</p>
1589+
<p>For NativeScript to recognize this new email-validator npm module, type <code>Ctrl+C</code> in your terminal to kill the existing <code>tns livesync</code> watcher if it’s still running, and then use <code>tns run</code> to rebuild your application and deploy it to an emulator or device.</p>
1590+
<pre><code>tns run ios --emulator
1591+
</code></pre><p>Or</p>
1592+
<pre><code>tns run android --emulator
1593+
</code></pre><p>After the app deploys you can again run the <code>livesync</code> command to setup the watcher again.</p>
1594+
<pre><code>tns livesync ios --emulator --watch
1595+
</code></pre><p>Or</p>
1596+
<pre><code>tns livesync android --emulator --watch
1597+
</code></pre><div class="exercise-end"></div>
1598+
1599+
<p>After your app launches again, if you type an invalid email address and attempt to login, you should see an alert that prevents the submission:</p>
1600+
<p><img src="images/chapter5/android/1.png" alt="Validation alert on Android">
1601+
<img src="images/chapter5/ios/1.png" alt="Validation alert on iOS"></p>
15851602
<p>In general npm modules greatly expand the number of things you&#39;re able to do in your NativeScript apps. Need date and time formatting? Use <a href="https://www.npmjs.com/package/moment">moment</a>. Need utility functions for objects and arrays? Use <a href="https://www.npmjs.com/package/lodash">lodash</a> or <a href="https://www.npmjs.com/package/underscore">underscore</a>. This code reuse benefit gets even more powerful when you bring NativeScript plugins into the picture.</p>
15861603
<blockquote>
15871604
<p><strong>WARNING</strong>: Not all npm modules work in NativeScript apps. Specifically, modules that depend on Node.js or browser APIs will not work, as those APIs do not exist in NativeScript. The NativeScript wiki contains a <a href="https://github.com/NativeScript/NativeScript/wiki/supported-npm-modules">list of some of the more popular npm modules that have been verified to work in NativeScript apps</a>.</p>

src/chapters/chapter5.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,44 @@ if (!this.user.isValidEmail()) {
7979

8080
<div class="exercise-end"></div>
8181

82-
Explain this code.
82+
Now, if the user attempts to login or register with an invalid email address, they’ll see an alert that points out the error. However in order to test out this change you’ll need to do one more thing.
8383

84-
TODO: Add images
84+
<h4 class="exercise-start">
85+
<b>Exercise</b>: Rebuild your app
86+
</h4>
87+
88+
As we mentioned in chapter 1.4, although the `tns livesync` command is smart enough to reload your app for most changes you make to your app, the command cannot hot reload your app for all changes—most notably, changes to native files in `app/App_Resources`, new modules installed with `npm install`, and new NativeScript plugins.
89+
90+
For NativeScript to recognize this new email-validator npm module, type `Ctrl+C` in your terminal to kill the existing `tns livesync` watcher if it’s still running, and then use `tns run` to rebuild your application and deploy it to an emulator or device.
91+
92+
```
93+
tns run ios --emulator
94+
```
95+
96+
Or
97+
98+
```
99+
tns run android --emulator
100+
```
101+
102+
After the app deploys you can again run the `livesync` command to setup the watcher again.
103+
104+
```
105+
tns livesync ios --emulator --watch
106+
```
107+
108+
Or
109+
110+
```
111+
tns livesync android --emulator --watch
112+
```
113+
114+
<div class="exercise-end"></div>
115+
116+
After your app launches again, if you type an invalid email address and attempt to login, you should see an alert that prevents the submission:
117+
118+
![Validation alert on Android](images/chapter5/android/1.png)
119+
![Validation alert on iOS](images/chapter5/ios/1.png)
85120

86121
In general npm modules greatly expand the number of things you're able to do in your NativeScript apps. Need date and time formatting? Use [moment](https://www.npmjs.com/package/moment). Need utility functions for objects and arrays? Use [lodash](https://www.npmjs.com/package/lodash) or [underscore](https://www.npmjs.com/package/underscore). This code reuse benefit gets even more powerful when you bring NativeScript plugins into the picture.
87122

0 commit comments

Comments
 (0)