Skip to content

Commit 9d7945e

Browse files
committed
docs(upgrade): updates based on review comments. preliminary description of DOM in hybrid apps.
1 parent 0dd1584 commit 9d7945e

File tree

4 files changed

+99
-25
lines changed

4 files changed

+99
-25
lines changed

public/docs/ts/latest/upgrade/index.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ include ../../../../_includes/_util-fns
1717

1818
One of the keys to a successful upgrade is to do it incrementally,
1919
by running the two frameworks side by side in the same application, and
20-
porting Angular 1 components to Angular 1 one by one. This makes it possible
20+
porting Angular 1 components to Angular 2 one by one. This makes it possible
2121
to upgrade even large and complex applications without disrupting other
2222
business, because the work can be done collaboratively and spread over
2323
a period of time. The [upgrade module in Angular 2](upgrade_adapter.html)

public/docs/ts/latest/upgrade/preparation.jade

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ include ../../../../_includes/_util-fns
5454
about during the upgrade. It also means we can start using TypeScript features
5555
in our Angular 1 code.
5656

57-
Since TypeScript is a superset of ECMAScript 6, which in turn is a superset
57+
Since TypeScript is a superset of ECMAScript 2015, which in turn is a superset
5858
of ECMAScript 5, switching to TypeScript doesn't necessarily mean anything
5959
else than intalling the TypeScript compiler and switching the extensions from
6060
`.js` to `.ts`. Just doing that is not hugely exciting though. The following
6161
steps will give us much more bang for the buck:
6262

6363
* For applications that use a module loader, TypeScript imports and exports
64-
(which are really ECMAScript 6 imports and exports) can be used to organize
64+
(which are really ECMAScript 2015 imports and exports) can be used to organize
6565
code into modules.
6666
* Type annotations can be gradually added to existing functions and variables
6767
to pin down their types and get all the benefits that brings, from built-time
6868
error checking to autocompletion and inline documentation.
69-
* ES6 features like `let`s and `const`s, default function parameters,
69+
* ES2015 features like `let`s and `const`s, default function parameters,
7070
and destructuring assignments can also be gradually added.
7171
* Services and Controller can be turned into *classes*. That way they'll be a step
7272
closer to becoming Angular 2 service component classes, which will make our life

public/docs/ts/latest/upgrade/tutorial.jade

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ include ../../../../_includes/_util-fns
9090
Since we're going to be writing our Angular 2 code in TypeScript, it makes sense to
9191
bring in the TypeScript compiler even before we begin upgrading.
9292

93-
In order to use TypeScript's ES6 module system to `import` and `export` code, we're
93+
In order to use TypeScript's ES2015 module system to `import` and `export` code, we're
9494
going to need a JavaScript module loader. Our application doesn't currently
9595
use one, and is just using plain old `<script>` tags and the global `window` scope
9696
instead. We'll replace this approach with the
@@ -135,8 +135,9 @@ include ../../../../_includes/_util-fns
135135
module using `System.import`. This will load and execute the `app/app.js` file.
136136

137137
We should also configure the TypeScript compiler so that it can understand our
138-
project. Add a `tsconfig.json` file to the `src` directory. It instructs the
139-
TypeScript compiler how to interpret our source files.
138+
project. We'll add a `tsconfig.json` file to the `src` directory, just like we did
139+
in the [Quickstart](../quickstart.html). It instructs the TypeScript compiler how
140+
to interpret our source files.
140141

141142
+makeJson('upgrade/ts/typescript-conversion/src/tsconfig.json', null, 'src/tsconfig.json')
142143

@@ -165,7 +166,7 @@ include ../../../../_includes/_util-fns
165166
departure from the previous approach which just relied on things being available
166167
on the global `window` scope.
167168

168-
Since TypeScript is a superset of ECMAScript 6, which in turn is a superset
169+
Since TypeScript is a superset of ECMAScript 2015, which in turn is a superset
169170
of ECMAScript 5, we can simply switch the file extensions from `.js` to `.ts`
170171
and define the imports and exports. We don't need to make other changes to
171172
our existing code. Instead we'll introduce type annotations and other new
@@ -377,9 +378,9 @@ include ../../../../_includes/_util-fns
377378
other features in addition to the imports and exports that we're already using.
378379
There's a lot of value the language can provide in Angular 1 applications.
379380

380-
For one thing, TypeScript is a superset of ES6. Any app that has previously
381+
For one thing, TypeScript is a superset of ES2015. Any app that has previously
381382
been written in ES5 - like the PhoneCat example has - can with TypeScript
382-
start incorporating all of the JavaScript features that are new to ES6.
383+
start incorporating all of the JavaScript features that are new to ES2015.
383384
These include things like `let`s and `const`s, default function parameters,
384385
and destructuring assignments.
385386

@@ -413,7 +414,7 @@ include ../../../../_includes/_util-fns
413414
easier once we do the upgrade.
414415

415416
Angular 1 expects controllers to be constructor functions, and that's what
416-
ES6/TypeScript classes really are, and that means we can just register a
417+
ES2015/TypeScript classes really are, and that means we can just register a
417418
class as a controller and Angular 1 will happily use it. We also won't
418419
need to make any changes to our test suite as the external behavior of the
419420
controllers will not change.
@@ -426,10 +427,10 @@ include ../../../../_includes/_util-fns
426427
What was previously done in the controller function is now done in the class
427428
constructor function. The class additionally declares three members: The
428429
array of phones, the name of the current sort key, and the search query. These
429-
are all things we we're attaching to `this`/`vm` earlier, but that weren't
430-
explicitly declared anywhere. The last one of these isn't actually used in the
431-
TypeScript code since it's only referred to in the template, but for the sake
432-
of clarity we want to define all the members our controller will have.
430+
are all things we have already been attaching to the controller,
431+
but that weren't explicitly declared anywhere. The last one of these isn't actually
432+
used in the TypeScript code since it's only referred to in the template, but for
433+
the sake of clarity we want to define all the members our controller will have.
433434

434435
In the Phone detail controller we'll have two members: One for the phone
435436
that the user is looking at and another for the URL of the currently displayed image.
@@ -443,6 +444,14 @@ include ../../../../_includes/_util-fns
443444
:marked
444445
This makes our controller code look a lot more like Angular 2 already. We're
445446
all set to actually introduce Angular 2 into the project.
447+
448+
If we had any Angular 1 services in the project, those would also be
449+
a good candidate for converting to classes, since like controllers,
450+
they're also constructor functions. But we only have the `Phone` factory
451+
in this project, and that's a bit special since it's an `ngResource`
452+
factory. So we won't be doing anything to it in the preparation stage,
453+
but will instead turn it directly into an Angular 2 service in the
454+
next section.
446455

447456
.l-main-section
448457
:marked
@@ -537,8 +546,9 @@ include ../../../../_includes/_util-fns
537546
+makeExample('upgrade/ts/ng2_initial/src/app/app.ts', 'bootstrap')
538547

539548
:marked
540-
We are now running both Angular 1 and 2 at the same time, though there are
541-
no Angular 2 components in it yet.
549+
We are now running both Angular 1 and 2 at the same time. That's pretty
550+
exciting! We're not running any actual Angular 2 components yet though,
551+
so let's do that next.
542552

543553

544554
:marked
@@ -595,9 +605,10 @@ include ../../../../_includes/_util-fns
595605

596606
:marked
597607
The `@Injectable` decorator will attach some dependency injection metadata
598-
to the class, letting Angular 2 know about its dependencies. This is
599-
a marker decorator we need to use for classes that have no other Angular 2
600-
decorators but still need to have their dependencies injected.
608+
to the class, letting Angular 2 know about its dependencies. As described
609+
by our [Dependency Injection Guide](../guide/dependency-injection.html),
610+
this is a marker decorator we need to use for classes that have no other
611+
Angular 2 decorators but still need to have their dependencies injected.
601612

602613
In its constructor the class expects to get the `Http` service. It will
603614
be injected to it and it is stored as a private field. The service is then
@@ -806,9 +817,16 @@ include ../../../../_includes/_util-fns
806817
These pipes do not exist in Angular 2, so we're going to need to do
807818
the filtering and sorting ourselves. Let's define a couple of pipes that
808819
get the job done.
809-
820+
821+
.alert.is-helpful
822+
:marked
823+
If you want to learn more about how pipes in Angular 2
824+
work, we have [a whole guide on the subject](../guide/pipes.html)
825+
available!
826+
827+
:marked
810828
For filtering, we'll have a pipe called `PhoneFilterPipe`. It works like
811-
`filter` in Angular 1 in that it filters a collection of objects,
829+
the `filter` filter in Angular 1 in that it filters a collection of objects,
812830
matching properties within the objects. But, as opposed to `filter`,
813831
this pipe is specialized to filter `Phone` objects and we can use
814832
type annotations to make this explicit:
@@ -858,7 +876,7 @@ include ../../../../_includes/_util-fns
858876

859877
:marked
860878
This is made possible by the `async` pipe, which we can apply in the template.
861-
I knows how to turn an Observable to the (latest) value it has emitted:
879+
It knows how to turn an Observable to the (latest) value it has emitted:
862880

863881
+makeExample('upgrade/ts/ng2_components/src/app/phone_list/phone_list.html', 'list', 'src/app/phone_list/phone_list.html')
864882

public/docs/ts/latest/upgrade/upgrade_adapter.jade

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,65 @@ table
6868
be downgraded. Again, the same singleton instances are shared. As you register the
6969
downgrade, you will explicitly specify a *string token* to be used in Angular 1.
7070

71-
### Components and DOM
71+
.alert.is-helpful Mention provider upgrades/downgrades
72+
73+
:marked
74+
### Components and the DOM
75+
76+
What we'll find in the DOM of a hybrid application are components and
77+
directives both from Angular 1 and Angular 2. These components
78+
communicate with each other by using the input and output bindings
79+
of their respective frameworks, which the `UpgradeAdapter` bridges
80+
together. They may also communicate through shared injected dependencies,
81+
as described above.
82+
83+
There are two key things to understand about what happens in the DOM
84+
of a hybrid application:
85+
86+
1. Every element in the DOM is owned by exactly one of the two
87+
frameworks. The other framework ignores it. If an element is
88+
owned by Angular 1, Angular 2 treats it as if it didn't exist,
89+
and vice versa.
90+
2. The root of the application *is always an Angular 1 template*.
91+
92+
So a hybrid application begins life as an Angular 1 application,
93+
and it is Angular 1 that processes its root template. How Angular 2 then steps
94+
into the picture is when somewhere in the Angular 1 application's
95+
templates an Angular 2 component is used. That component's view will
96+
then be managed by Angular 2, and may use any number of Angular 2
97+
components and directives.
98+
99+
After that, we may interleave the two frameworks as much as we need to,
100+
and we cross the boundary between the two frameworks by two alternative
101+
ways:
102+
103+
1. By using a component from the other framework: An Angular 1 template
104+
using an Angular 2 component, or an Angular 2 template using an
105+
Angular 1 component.
106+
2. By transcluding or projecting content from the other framework. When
107+
an Angular 1 template uses an Angular 2 component, it may *transclude*
108+
content into it. The Angular 2 component then uses Angular 2 *content
109+
projection* to attach it somewhere. The `UpgradeAdapter` bridges
110+
Angular 1 transclusion to Angular 2 content projection, and vice versa.
111+
112+
Whenever you use a component that belongs to the other framework, a
113+
switch between framework boundaries occurs. However, that switch only
114+
happens to the *children* of the component element. When you use an
115+
Angular 2 component from Angular 1 like this:
116+
117+
```
118+
<ng2-component></ng2-component>
119+
```
120+
121+
The element `ng2-component` will remain to be an Angular 1 managed
122+
element, because it's defined in an Angular 1 template. That also
123+
means you can apply additional Angular 1 directives to it, but not
124+
Angular 2 directives. It is in the view of the `Ng2Component` component,
125+
where Angular 2 is used, so the child elements of `ng2-component` will
126+
live in Angular 2 land.
72127

73-
.alert.is-helpful On component adapters. Element ownership. Transclusion / content projection.
128+
This same rule also applies when you use Angular 1 component directives
129+
from Angular 2.
74130

75131
:marked
76132
### Change Detection

0 commit comments

Comments
 (0)