gistlib
index.tsxclass StateManager { constructor(initialState) { this.state = initialState; } // Method to get the current state getState() { return this.state; } // Method to update the state setState(newState) { this.state = newState; } // Method to reset the state to initial state resetState() { this.state = initialState; } // You can add more methods based on your requirements } // Sample usage const initialState = { count: 0 }; const stateManager = new StateManager(initialState); console.log(stateManager.getState()); // Output: { count: 0 } stateManager.setState({ count: 1 }); console.log(stateManager.getState()); // Output: { count: 1 } stateManager.resetState(); console.log(stateManager.getState()); // Output: { count: 0 } 827 chars34 lines
class StateManager { constructor(initialState) { this.state = initialState; } // Method to get the current state getState() { return this.state; } // Method to update the state setState(newState) { this.state = newState; } // Method to reset the state to initial state resetState() { this.state = initialState; } // You can add more methods based on your requirements } // Sample usage const initialState = { count: 0 }; const stateManager = new StateManager(initialState); console.log(stateManager.getState()); // Output: { count: 0 } stateManager.setState({ count: 1 }); console.log(stateManager.getState()); // Output: { count: 1 } stateManager.resetState(); console.log(stateManager.getState()); // Output: { count: 0 }
gistlibby LogSnag