expensiveOperation('Scott'); // Scott expensiveOperation('Scott'); expensiveOperation('Scott'); expensiveOperation('Scott'); expensiveOperation('Scott'); expensiveOperation('John'); // John expensiveOperation('John'); expensiveOperation('Aya'); // Aya expensiveOperation('Aya'); expensiveOperation('John'); // John expensiveOperation('John');
More in practice. Here we want to do mutate only when the window.innerWidth
or windowHeight has changed.
letupdateCanvasSize = func.runOnceOnChange( (windowWidth, windowHeight)=> { // Do something expensive. console.log('Change the canvas size'); })
Runs a function ONLY when the parameters have changed.
Running the below, you will see only four console.logs executed, each when the params have changed.
More in practice. Here we want to do mutate only when the window.innerWidth or windowHeight has changed.
You can implement this for a class method as follows