Skip to content

Commit 04ae9af

Browse files
committed
Working on the segue from 3/4 and a few other minor edits
1 parent 9af7180 commit 04ae9af

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

index.html

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,12 +1068,13 @@ <h4 class="exercise-start">
10681068
<blockquote>
10691069
<p><strong>TIP</strong>: There are other ways to share code between native and web apps besides the <code>shared</code> folder convention Groceries uses. For an approach that places web and native code in the same codebase, that also provides some additional tooling around testing and internationalization, check out <a href="https://github.com/NathanWalker/angular2-seed-advanced">Nathan Walker’s advanced Angular 2 seed project</a>.</p>
10701070
</blockquote>
1071-
<p>And we’re just getting started. NativeScript provides a number of other ways to tie into native device functionality out of the box through NativeScript modules. Let’s look at how they work.</p>
1071+
<p>Now that we’ve discussed how NativeScript apps and Angular 2 web apps are similar, let’s move onto how they’re different. When you’re building with NativeScript you have access to the entirety of iOS and Android, as well as the highly capable devices they run on—enabling you to build rich experiences that go above and beyond what the web can offer.</p>
1072+
<p>The best part is, one NativeScript feature makes it trivial to tie into this native device functionality: NativeScript modules.</p>
10721073

10731074
</div>
10741075
<div class="chapter">
10751076
<h2 id="nativescript-modules">NativeScript modules</h2>
1076-
<p>In this chapter you&#39;ll learn about NativeScript modules, which are the JavaScript modules in your app&#39;s <code>node_modules/tns-core-modules</code> folder. Whether you&#39;ve realized it or not, you&#39;ve already used several NativeScript modules, as all of the NativeScript UI elements are actually implemented with JavaScript code.</p>
1077+
<p>In this chapter you&#39;ll learn about NativeScript modules, which are the TypeScript modules in your app&#39;s <code>node_modules/tns-core-modules</code> folder. Whether you&#39;ve realized it or not, you&#39;ve already used several NativeScript modules, as all of the NativeScript UI elements are actually implemented with TypeScript code.</p>
10771078
<p>If you dig into <code>node_modules/tns-core-modules</code> you can get an idea of how these modules work. Start by finding the <code>node_modules/tns-core-modules/camera</code> folder, which includes the implementation of the camera module. It includes:</p>
10781079
<ul>
10791080
<li>a <code>package.json</code> file that sets the name of the module;</li>
@@ -1082,7 +1083,11 @@ <h2 id="nativescript-modules">NativeScript modules</h2>
10821083
<li>a file containing code shared by the Android and iOS implementations (<code>camera-common.js</code>)</li>
10831084
</ul>
10841085
<blockquote>
1085-
<p><strong>NOTE</strong>: You can refer to the <a href="https://nodejs.org/api/modules.html#modules_folders_as_modules">Node.js documentation on folders as modules</a> for more detailed information on how NativeScript organizes its modules.</p>
1086+
<p><strong>NOTE</strong>:</p>
1087+
<ul>
1088+
<li>You can refer to the <a href="https://nodejs.org/api/modules.html#modules_folders_as_modules">Node.js documentation on folders as modules</a> for more detailed information on how NativeScript organizes its modules.</li>
1089+
<li>The “tns-core-modules” package only includes compiled JavaScript code to cut down on file size. You can find the TypeScript code for each of these modules in the `<a href="https://github.com/NativeScript/nativescript">main NativeScript GitHub repo</a>, for instance here’s the <a href="https://github.com/NativeScript/NativeScript/tree/master/camera">camera module’s source code</a>.</li>
1090+
</ul>
10861091
</blockquote>
10871092
<p>The <code>*.ios.*</code> and <code>*.android.*</code> naming convention should look familiar, as it’s the exact same convention we used to include Android- and iOS-specific styling in <a href="#css">chapter 2.3</a>. NativeScript uses this same convention to implement its modules on iOS and Android. Now that you know where these modules are, let&#39;s take a closer look at what else they can do for your app, starting with a closer looks at what you can do with NativeScript’s UI elements.</p>
10881093
<h3 id="ui-elements">UI elements</h3>
@@ -1095,24 +1100,27 @@ <h4 class="exercise-start">
10951100
<pre><code class="lang-TypeScript">import {topmost} from &quot;ui/frame&quot;;
10961101
import {Page} from &quot;ui/page&quot;;
10971102
</code></pre>
1103+
<blockquote>
1104+
<p><strong>NOTE</strong>: All of the imports you’ve seen to this point work because the TypeScript compiler resolves them against your project’s <code>node_modules</code> folder. For instance, <code>import {Component} from &quot;angular2/core&quot;</code> works because a <code>node_modules/angular2/core.d.ts</code> file exists. The two imports above are NativeScript module imports, and they work because your project’s <code>references.d.ts</code> file includes a reference to a TypeScript declaration file (a <code>.d.ts</code> file), that lives in <code>node_modules/tns-core-modules</code>, and which allows you to import modules from <code>node_modules/tns-core-modules</code> without any prefixes.</p>
1105+
</blockquote>
10981106
<p>Next, alter the same file’s existing <code>&quot;angular2/core&quot;</code> import to include the <code>OnInit</code> interface:</p>
10991107
<pre><code class="lang-TypeScript">import {Component, OnInit} from &quot;angular2/core&quot;;
11001108
</code></pre>
11011109
<p><code>OnInit</code> is a <a href="http://www.typescriptlang.org/docs/handbook/interfaces.html#class-types">TypeScript class interface</a>. To see how it works, make the following change to the declaration of your <code>LoginPage</code> class:</p>
11021110
<pre><code class="lang-TypeScript">export class LoginPage implements OnInit {
11031111
</code></pre>
1104-
<p>If you’re using an editor that supports TypeScript, you should see an error that says something like <em>“Class ‘LoginPage’ incorrectly implements interface ‘OnInit’”</em>. When you implement a TypeScript class interface, you’re telling the TypeScript compiler that you will implement any of the methods that the interface requires. In the case of <code>OnInit</code>, Angular 2 requires you to implement a single <code>ngOnInit()</code> method. To implement it, add the following code within the <code>LoginPage</code> class:</p>
1112+
<p>If you’re using an editor that supports TypeScript, you should see an error that says something like <em>“Class ‘LoginPage’ incorrectly implements interface ‘OnInit’”</em>. When you implement a TypeScript class interface, you’re telling the TypeScript compiler that you must implement all methods that the interface requires. In the case of <code>OnInit</code>, Angular 2 requires you to implement a single <code>ngOnInit()</code> method. To implement it, add the following code within the <code>LoginPage</code> class:</p>
11051113
<pre><code class="lang-TypeScript">ngOnInit() {
11061114
this.page = &lt;Page&gt;topmost().currentPage;
11071115
this.page.actionBarHidden = true;
11081116
this.page.backgroundImage = this.page.ios ? &quot;res://bg_login.jpg&quot; : &quot;res://bg_login&quot;;
11091117
}
11101118
</code></pre>
11111119
<blockquote>
1112-
<p><strong>NOTE</strong>: The <code>this.page.ios</code> in this function can go away after NativeScript 2.0 is released. The check is there because of <a href="https://github.com/NativeScript/NativeScript/issues/1788">this bug</a>.</p>
1120+
<p><strong>NOTE</strong>: The <code>this.page.ios</code> check in this function can go away after NativeScript 2.0 is released. The check is there because of <a href="https://github.com/NativeScript/NativeScript/issues/1788">this bug</a>.</p>
11131121
</blockquote>
11141122
<p><code>ngOnInit</code> is one of several <a href="https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html">component lifecycle hooks</a> that Angular 2 provides. As its name implies, <code>ngOnInit</code> gets invoked when Angular initializes this component.</p>
1115-
<p>We’ll discuss what the code within <code>ngOnInit()</code> does momentarily, but finally, to make these changes compile and run, add the following property to the <code>LoginPage</code> class. (You can put it right under the <code>user: User;</code> line.)</p>
1123+
<p>We’ll discuss what the code within <code>ngOnInit()</code> does momentarily, but finally, to make these changes compile and run, add the following property to the <code>LoginPage</code> class. You can put it right under the <code>user: User;</code> line.</p>
11161124
<pre><code class="lang-TypeScript">page: Page;
11171125
</code></pre>
11181126
<div class="exercise-end"></div>

src/chapters/chapter3.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,4 +652,6 @@ The power of NativeScript is you have the ability to use the same Angular conven
652652
653653
> **TIP**: There are other ways to share code between native and web apps besides the `shared` folder convention Groceries uses. For an approach that places web and native code in the same codebase, that also provides some additional tooling around testing and internationalization, check out [Nathan Walker’s advanced Angular 2 seed project](https://github.com/NathanWalker/angular2-seed-advanced).
654654
655-
And we’re just getting started. NativeScript provides a number of other ways to tie into native device functionality out of the box through NativeScript modules. Let’s look at how they work.
655+
Now that we’ve discussed how NativeScript apps and Angular 2 web apps are similar, let’s move onto how they’re different. When you’re building with NativeScript you have access to the entirety of iOS and Android, as well as the highly capable devices they run on—enabling you to build rich experiences that go above and beyond what the web can offer.
656+
657+
The best part is, one NativeScript feature makes it trivial to tie into this native device functionality: NativeScript modules.

src/chapters/chapter4.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## NativeScript modules
22

3-
In this chapter you'll learn about NativeScript modules, which are the JavaScript modules in your app's `node_modules/tns-core-modules` folder. Whether you've realized it or not, you've already used several NativeScript modules, as all of the NativeScript UI elements are actually implemented with JavaScript code.
3+
In this chapter you'll learn about NativeScript modules, which are the TypeScript modules in your app's `node_modules/tns-core-modules` folder. Whether you've realized it or not, you've already used several NativeScript modules, as all of the NativeScript UI elements are actually implemented with TypeScript code.
44

55
If you dig into `node_modules/tns-core-modules` you can get an idea of how these modules work. Start by finding the `node_modules/tns-core-modules/camera` folder, which includes the implementation of the camera module. It includes:
66

@@ -9,7 +9,9 @@ If you dig into `node_modules/tns-core-modules` you can get an idea of how these
99
- a file containing the module's iOS implementation (`camera.ios.js`);
1010
- a file containing code shared by the Android and iOS implementations (`camera-common.js`)
1111

12-
> **NOTE**: You can refer to the [Node.js documentation on folders as modules](https://nodejs.org/api/modules.html#modules_folders_as_modules) for more detailed information on how NativeScript organizes its modules.
12+
> **NOTE**:
13+
> * You can refer to the [Node.js documentation on folders as modules](https://nodejs.org/api/modules.html#modules_folders_as_modules) for more detailed information on how NativeScript organizes its modules.
14+
> * The “tns-core-modules” package only includes compiled JavaScript code to cut down on file size. You can find the TypeScript code for each of these modules in the `[main NativeScript GitHub repo](https://github.com/NativeScript/nativescript), for instance here’s the [camera module’s source code](https://github.com/NativeScript/NativeScript/tree/master/camera).
1315
1416
The `*.ios.*` and `*.android.*` naming convention should look familiar, as it’s the exact same convention we used to include Android- and iOS-specific styling in [chapter 2.3](#css). NativeScript uses this same convention to implement its modules on iOS and Android. Now that you know where these modules are, let's take a closer look at what else they can do for your app, starting with a closer looks at what you can do with NativeScript’s UI elements.
1517

@@ -28,6 +30,8 @@ import {topmost} from "ui/frame";
2830
import {Page} from "ui/page";
2931
```
3032

33+
> **NOTE**: All of the imports you’ve seen to this point work because the TypeScript compiler resolves them against your project’s `node_modules` folder. For instance, `import {Component} from "angular2/core"` works because a `node_modules/angular2/core.d.ts` file exists. The two imports above are NativeScript module imports, and they work because your project’s `references.d.ts` file includes a reference to a TypeScript declaration file (a `.d.ts` file), that lives in `node_modules/tns-core-modules`, and which allows you to import modules from `node_modules/tns-core-modules` without any prefixes.
34+
3135
Next, alter the same file’s existing `"angular2/core"` import to include the `OnInit` interface:
3236

3337
```TypeScript
@@ -40,7 +44,7 @@ import {Component, OnInit} from "angular2/core";
4044
export class LoginPage implements OnInit {
4145
```
4246
43-
If you’re using an editor that supports TypeScript, you should see an error that says something like *“Class ‘LoginPage’ incorrectly implements interface ‘OnInit’”*. When you implement a TypeScript class interface, you’re telling the TypeScript compiler that you will implement any of the methods that the interface requires. In the case of `OnInit`, Angular 2 requires you to implement a single `ngOnInit()` method. To implement it, add the following code within the `LoginPage` class:
47+
If you’re using an editor that supports TypeScript, you should see an error that says something like *“Class ‘LoginPage’ incorrectly implements interface ‘OnInit’”*. When you implement a TypeScript class interface, you’re telling the TypeScript compiler that you must implement all methods that the interface requires. In the case of `OnInit`, Angular 2 requires you to implement a single `ngOnInit()` method. To implement it, add the following code within the `LoginPage` class:
4448

4549
``` TypeScript
4650
ngOnInit() {
@@ -50,11 +54,11 @@ ngOnInit() {
5054
}
5155
```
5256

53-
> **NOTE**: The `this.page.ios` in this function can go away after NativeScript 2.0 is released. The check is there because of [this bug](https://github.com/NativeScript/NativeScript/issues/1788).
57+
> **NOTE**: The `this.page.ios` check in this function can go away after NativeScript 2.0 is released. The check is there because of [this bug](https://github.com/NativeScript/NativeScript/issues/1788).
5458

5559
`ngOnInit` is one of several [component lifecycle hooks](https://angular.io/docs/ts/latest/guide/lifecycle-hooks.html) that Angular 2 provides. As its name implies, `ngOnInit` gets invoked when Angular initializes this component.
5660

57-
Well discuss what the code within `ngOnInit()` does momentarily, but finally, to make these changes compile and run, add the following property to the `LoginPage` class. (You can put it right under the `user: User;` line.)
61+
Well discuss what the code within `ngOnInit()` does momentarily, but finally, to make these changes compile and run, add the following property to the `LoginPage` class. You can put it right under the `user: User;` line.
5862

5963
``` TypeScript
6064
page: Page;

0 commit comments

Comments
 (0)