Curry to toggle boolean on array changes

Curry to toggle boolean on array changes

by Nirvanachain

JavaScript

var isDisabled = true;
var negativeTerms = [];

function onChangeNegativeTerms(terms) {
	negativeTerms = terms;
	console.log(isDisabled, negativeTerms);
}

// curry function to help set isDisabled to false
function onArrayChange(func) {
  console.log(isDisabled); //initially will be true
  return function() {
  	isDisabled = false;
  	func.apply(this, [...arguments])
  }
}

changeNegativeTerms = onArrayChange(onChangeNegativeTerms);
changeNegativeTerms(['123', '456']);