0
0
Angularframework~10 mins

Facade service pattern in Angular - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to inject the facade service into the component constructor.

Angular
constructor(private [1]: UserFacade) {}
Drag options to blanks, or click blank then click option'
AuserFacade
BUserFacade
CfacadeUser
Duser_service
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of a variable name.
Using underscores in variable names.
Capitalizing the first letter of the variable.
2fill in blank
medium

Complete the code to call the facade's method to load users inside ngOnInit.

Angular
ngOnInit() {
  this.userFacade.[1]();
}
Drag options to blanks, or click blank then click option'
AfetchUsers
BloadUsers
CgetUsers
DretrieveUsers
Attempts:
3 left
💡 Hint
Common Mistakes
Using method names that are not defined in the facade.
Using verbs like 'get' or 'fetch' which might not be the facade's method.
3fill in blank
hard

Fix the error in the facade service method to return the users observable.

Angular
getUsers(): Observable<User[]> {
  return this.store.[1](selectUsers);
}
Drag options to blanks, or click blank then click option'
Apipe
Bdispatch
Cselect
Dsubscribe
Attempts:
3 left
💡 Hint
Common Mistakes
Using dispatch which is for sending actions, not selecting data.
Using subscribe inside the facade which breaks observable chaining.
4fill in blank
hard

Fill both blanks to create a facade method that dispatches an action to add a user.

Angular
addUser(user: User) {
  this.store.[1](new [2](user));
}
Drag options to blanks, or click blank then click option'
Adispatch
Bselect
CAddUserAction
DLoadUsersAction
Attempts:
3 left
💡 Hint
Common Mistakes
Using select instead of dispatch.
Using the wrong action name that does not add a user.
5fill in blank
hard

Fill all three blanks to create a facade observable for users with error handling.

Angular
users$ = this.store.[1](selectUsers).[2](catchError(() => of([])));

constructor(private store: Store) {
  this.users$ = this.users$.[3]();
}
Drag options to blanks, or click blank then click option'
Aselect
Bpipe
CshareReplay
Ddispatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using dispatch instead of select.
Not using pipe to chain operators.
Forgetting to share the observable with shareReplay.