- "Pragmatic Programmer"-framed view of all the cool new Angular developer stuff
- get up and running as soon as possible with Angular2, TypeScript, Rx, Relay, etc.
- Learn JS before Angular or any other framework, and learn ES5 before ES6
- understand problems solved by new language features to apply them well
- understand problems, tradeoffs, and designs of framework
- don't default to creating classes everywhere; take advantage of JS being conducive to other styles, namely functional
Broken Windows
- Angular1 module(?) system and abuses
- directive API
- "Rubber Duck Debugging" from Pragmatic Programmer
- thinking differently and pragmatically about what you're writing
- thinking about publicly exposed interface
- treating the UI as a Domain model instead of a picture
- WhyFP quote: "It is now generally accepted that modular design is the key to successful programming...", goes on to cite evidence from a bunch of old languages I've never heard of.
- internal open source model
- helps you think about the Law of Demeter; components should have limited knowledge, and only talk to its friends
- DOM as DSL was possible in Angular1, now conventional and encouraged
- goes back to the "always learning" principle; these look like React events. Explore other stuff to better understand
- ES6 template strings in code files
- kind of React/JSX-y, bringing DOM to code
- Pragmatic Principle: Refactor Early, Refactor Often
- when you add a couple functions and elements to the same file to implement a requirement, becomes clear quickly if refactor is necessary
- Pragmatic Principle: Configure, don’t integrate
- Stone Soup: dynamic component discovery through metadata and TypeScript
- the difference between a domain-driven design service and common Angular 1 usages
- Angular2 encourages to a less-overloaded, more common definition of "service"
RestoreService
in Tour of Heroes example is great Pragmatic application
- Angular's Testing emphasis helps achieve Pragmatic Principle "Design to test"; don't ignore it
In pragmatic fashion, take some ES2015 features and try to think of them in an Angular context. (Also TypeScript, since ES2015 == TypeScript in many cases)
Disclaimer most of these things are "Stone Soup"; I haven't tried them, they're just connections I've made while learning Angular2, ES2015, TypeScript, etc.
- similar to metadata, emphasizes Pragmatic Principle: "Configure, don't integrate"
- Nightmares: the first time you unexpectedly encounter variable hoisting in JavaScript
- angular had polyfilled constants, so they must be a good thing, right?
var vm = this
kinda controversial- arrow functions prevent
.bind(this)
-everywhere syndrome
- apps composed of components from many different teams in overlapping bounded contexts are bound to overlap. Use symbols to localize properties without crazy underscore/$ prefixes
- also allows a kind of interface definition in language spec itself
- interoperability! previously we had:
- john resig's implementation http://ejohn.org/blog/simple-javascript-inheritance/
angular.extend
,_.extend
angular.factory
orangular.value
wrapping constructor functions- about a million others
- still important to understand prototypical inheritance
- caution: don't start creating messy inheritance trees and gobs of state
- worth noting Douglas Crockford's opinion: "I have been writing JavaScript for 14 years now, and I have never once found need to use an uber function. The super idea is fairly important in the classical pattern, but it appears to be unnecessary in the prototypal and functional patterns. I now see my early attempts to support the classical model in JavaScript as a mistake." http://www.crockford.com/javascript/inheritance.html
- similar to Classes, encourages interoperability. see: https://promisesaplus.com/implementations for a list of all the various a+ implementations
- environment-specific data sources, similar to using H2 in a Java development environment
- really hard in Angular1/Grunt or Gulp
- pattern matching to include/exclude files from build
- really hard in Angular1/Grunt or Gulp
- [] new Set(iterable)
- convert an array to a set and eliminate duplicate values with a single line of native code
- pass it a generator; run to completion and put yielded values into a set
- avoids memory leaks caused by insufficient garbage cleanup; e.g. Angular1 event
listener not cleaned up on
$scope.$on('$destroy')
would leak because callback would still be registered. A WeakSet could help avoid this problem.
$q
only kinda solves callback hell- asynchronous code is awesome; synchronous is easier to read
- https://basarat.gitbooks.io/typescript/content/docs/why-typescript.html#types-are-structural
- kind of like an
isA
function you might write, but without writing it
- TypeScript Deep Dive: https://basarat.gitbooks.io/typescript/
- Mozilla ES6 in-depth: Mozilla ES6 in-depth series: https://hacks.mozilla.org/category/es6-in-depth/
- The Pragmatic Programmer: http://www.amazon.com/The-Pragmatic-Programmer-Journeyman-Master/dp/020161622X