Giter Site home page Giter Site logo

angular-patterns-workshop's Introduction

CI

Angular patterns workshop

A workshop about beginner and intermediate Angular patterns.

Getting started

Open and follow the slide deck at https://nearform.github.io/angular-patterns-workshop/.

Running locally

Requirements

Setup

  • Clone this repository
  • Add a TMDB API key:
    • Sign up to The Movie Database
    • Make a note of your API key at Settings -> API -> Request an API Key -> Developer -> API Key (v3 auth)
    • Copy apps/movies/src/environments/environment.ts to apps/movies/src/environments/environment.development.ts
    • Update the apiKey property with the value of your API key
  • npm i
  • npm run movies to start the application
    • To complete the exercises you will need to be signed in to TMDB
    • To sign in, select the "Login" button in the top right of the UI
  • npm run slides to start the slide deck (optional)

angular-patterns-workshop's People

Contributors

akallabet avatar allforabit avatar bredikhin avatar dependabot[bot] avatar ekynoxe avatar g100g avatar grantmorrison avatar hizo avatar ianlnf avatar melkornemesis avatar williamlines avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

codeflyer

angular-patterns-workshop's Issues

Workshop slides: step 4 render a list of movies

New concepts

  • *ngIf
  • Angular pipes
  • Angular async pipe
  • *ngFor
  • Template interpolation ({{movie.description}})

The challenge

Render a basic list of popular movies based on the response from tmdb. Feel free to use material cards to add some formatting to each item and also the stack utility class on the container to add some space between items.

Trying it out

View the rendered list in the browser

Workshop slides: step 7 add an "Add to watchlist" service method

New concepts

  • RxJs throwError (when user id is not available)
  • Angular event binding

Challenge

Create a new service method that post to the watchlist tmdb endpoint and do a basic call when a button is clicked in the UI

Trying it out

Click the button and observe the network panel in dev tools to ensure a 201 is correctly returned

Workshop slides: step 10 auto refresh on updating watchlist

New concepts

  • None

Challenge

Refresh the watch list query automatically when the user adds an item to their watchlist. As a bonus show a "Remove from watchlist" button when the item is already added and remove the item from their watchlist when this is clicked.

Trying it out

Try adding an item to your watch list. The UI should now automatically update (after a slight delay for request to complete).

Workshop slides: step 6 add a loading indicator

New concepts

  • RxJs startWith
  • ngIf negation - *ngIf="!movies.isLoading"

Challenge

Add a loading indicator to show before the popular movies request has completed

Trying it out

Simulate a slow network delay in browser DevTools and load the page or add a delay in the observable pipe before returning the result

Workshop slides: step 2 creating a service

New concepts

  • Angular service
  • Angular http
  • Angular dependency injection
  • RxJs Observables pipe and map
  • RxJs subscription

Challenge

  • Create a service that uses the ApiService to call the popular movies endpoint, subscribe in the component and log the results of the call

Trying it out

View the results in the browser console log

Customise nx generator config so it is tuned for workshop

The NX generator config should be tuned so that it works well for the workshop, reflects the solution structures, puts the files in the correct folder and doesn't create too much boilerplate.

  • Change the default directory to start-here directory
  • Include flag no tests
  • Include flag no style
  • Include flag to make the component structure flat
  • Include flag to put template inline

We should also mention that the config has been tuned slightly in the README or the slides or both.

Workshop slides: step 9 combine data from the watchlist endpoint with the the popular movies list

New concepts

  • RxJs combineLatest
  • RxJs subject that emits values (movie ids)

Challenge

Combine data from two observable sources to create a single observable that merges data from both the popular movies list and the watchlist endpoint. Disable the "Add to watchlist" button if the movie is already on the users watchlist.

Trying it out

Try adding an item to your watchlist and then refresh the page and the button should now be disabled if it's already on the watch list

Workshop: misc text fixes for slides

  • Path is incorrect for start here in some places
  • Slide 6, replace an "and" with a comma
  • Update Readme with new commands and updated instructions
  • withWatchListFlag -> withWatchlistFlag (casing) in slides
  • "Day to day" -> "When working with Angular"
  • Slide 8 change "async behaviours are" -> "async behaviour is"
  • Slide 9 link to tmdb api docs
  • Mention that you have to be logged in to tmdbs in README and a slide

Workshop slides: step 3 unsubscribe to a service on component destroy

New concepts

  • Angular component OnDestroy life cycle
  • RxJs subject
  • RxJs delay and takeUntil operators
  • RxJs subscribe with object syntax {next: (v) => {}, complete: () => {}}

Challenge

Unsubscribe from the popular movies observable when the component is destroyed. To simulate a slow network temporarily add a delay operator with a long time out (e.g. 10 seconds) and ensure that the stream is completed automatically if you navigate away from the page. Use complete callback to see when the stream has been completed.

Trying it out

Load the page and before the query has completed navigate away (e.g. by clicking the top right home button) and observe that the completed callback is immediately called, cancelling any requests that may be in flight.

Code examples and UX

Step 2: Trying it out - there's space to redistribute the example of the service

Overall, there's room for more code examples when talking about different available functions.

The description in step 2 really minimizes what the output will really be. See where more guidance can be provided.

Workshop slides: step 1 angular component

See https://nearform.github.io/react-patterns-workshop/6 for an idea of how much detail to include.

The basic format is:

  • some background information about the topic
  • details about the exercise
  • instructions on trying it out

Challenge

Write a component that displays "Hello world!!!" on the page.

New concepts

  • Angular component
  • Angular templates
  • Standalone components

Trying it out

Can try it out by viewing it in the browser

Workshop: step 5 slide improvements

  • Mention about copy pasting html from movie list component
  • Hint about using ! for the movie input
  • Mention using the flex class to place image beside the description

Workshop slides: step 5 add a poster image

New concepts

  • Property binding: [src]="movie.poster" and [alt]="movie.title"
  • More complex dom elements in Angular

Challenge

Add an image to go alongside the movie title and description

Trying it out

Can be viewed in the browser

Notes

Not many new concepts here, could possibly have user put the movie card into a new component???

Workshop slides: step 8 "Add to watchlist" unsubscribe on component destroy

New concepts

  • switchMap

Challenge

Unsubscribe from the post to add a movie to your watchlist when the component is destroyed.

Trying it out

Introduce a false delay to the api post service and navigate away after clicking the button and observe that the stream is completed immediately and the call to the endpoint is cancelled or never occurs.

Note

Similar to step 3 but will require using an advanced RxJs operator switchMap: https://blog.angular-university.io/rxjs-switchmap-operator/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.