Hard
Implement the missing transition logic in this state machine:
1class StateMachine {2 constructor(initialState, transitions) {3 this.currentState = initialState;4 this.transitions = transitions;5 this.history = [];6 this.subscribers = new Set();7 }89 transition(event, payload = {}) {10 const currentTransitions = this.transitions[this.currentState];11 _______________________12 _______________________13 _______________________14 _______________________15 }1617 subscribe(callback) {18 this.subscribers.add(callback);19 return () => this.subscribers.delete(callback);20 }21}2223const machine = new StateMachine('idle', {24 idle: {25 START: { target: 'running', action: () => console.log('Starting...') },26 ERROR: { target: 'error' }27 },28 running: {29 PAUSE: { target: 'paused' },30 COMPLETE: { target: 'completed' },31 ERROR: { target: 'error' }32 }33});