- Create a
command$
observable of all inputs (counterUI.btnStart$, counterUI.btnPause$, counterUI.inputTickSpeed, etc..) and map them to state updates i.e. counterUI.btnStart$.pipe(mapTo({isTicking: true})) - Create a
state$
observable. Start with initialConterState, use scan to merge updates from command$ in. Use shareReplay(1) to retrieve the last value emitted whenever you subscribe. - Subscribe to state$ and use console.log to test it.
- Create a
renderCountValue$
observable in section "SIDE EFFECTS" - "Input". Usetap
to execute counterUI.renderDisplayText(). To optimize performance use thequeryChange
custom operator. - Place the new observable in the "SUBSCRUPTIONS" section under "Input" to test it.
- Create a
timerProcessChange$
observable in the section "OBSERVABLES". - Use the
state$
to get the isTicking value. Use the "switchMap NEVER" pattern from before to start a timer. - Create a
programmaticCommands
subject in section "STATE" - "Command" - Create a
handleTimerProcessChange$
observable in section "SIDE EFFECTS" - "Outputs". Use thetap
operator to callnext()
onprogrammaticCommands
Explore the counterUI API by typing counterUI.
somewhere in the index.ts file. ;)
Implement all the features of the counter:
- Start, pause the counter. Then restart the counter (+)
- Start it again from the paused number (++)
- If Set to button is clicked set counter value to input value while counting (+++)
- Reset to initial state if the reset button is clicked (+)
- Is count up button is clicked count up (+)
- Is count down button is clicked count down (+)
- Change interval if input tickSpeed input changes (++)
- Change count up if input countDiff changes (++)
- Take care of rendering execution and other performance optimizations (+)
Some structure recommendations
// == CONSTANTS =========================================================== // = BASE OBSERVABLES ==================================================== // == SOURCE OBSERVABLES ================================================== // === STATE OBSERVABLES ================================================== // === INTERACTION OBSERVABLES ============================================ // == INTERMEDIATE OBSERVABLES ============================================ // = SIDE EFFECTS ========================================================= // == UI INPUTS =========================================================== // == UI OUTPUTS ========================================================== // == SUBSCRIPTION ======================================================== // === INPUTs ============================================================= // === OUTPUTS ============================================================ // = HELPER =============================================================== // = CUSTOM OPERATORS ===================================================== // == CREATION METHODS ==================================================== // == OPERATORS ===========================================================