0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 12:18:54 +02:00

client: Add a toggle() functional util.

This commit is contained in:
Jason Volk 2017-12-12 13:21:43 -07:00
parent 0565301560
commit 5b2facd8e3

View file

@ -121,6 +121,16 @@ let mayif = (test = () => true, closure = () => undefined) =>
return maybe(() => closure(test())); return maybe(() => closure(test()));
}; };
/**
*/
let toggle = (obj, key, value = undefined) =>
{
if(value === undefined)
obj[key] =! obj[key];
else
obj[key] = value;
};
/** /**
* Like "toggle" but prunes the object of the key when switching * Like "toggle" but prunes the object of the key when switching
* to the false state. * to the false state.