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:
parent
0565301560
commit
5b2facd8e3
1 changed files with 10 additions and 0 deletions
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue