BACK
PracticeInterview: withLatestFrom() submit + token
PRACTICE · 22 · 練

Interview: withLatestFrom() submit + token

On submit, take the latest auth token and build the string save:token-1.

  1. Solve the task in the editor — no long theory.
  2. Run the check and compare your output with the expected result.
  3. Stuck? Open the solution and carry the approach into your own code.
Solution spoiler · click to reveal
const { of, withLatestFrom, map } = Rx;

const submit$ = of('save');
const token$ = of('token-1');

const result$ = submit$.pipe(
  withLatestFrom(token$),
  map(([action, token]) => action + ':' + token)
);

result$.subscribe(value => console.log(value));
script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...