lodash#union JavaScript Examples
The following examples show how to use
lodash#union.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: store.js From space-station-13-idle with GNU Affero General Public License v3.0 | 6 votes |
// Needed to Vue.set appropriately
function customMerge(obj, source, root = true, softReset = false) {
let allKeys = Object.keys(source);
if (obj.constructor == Object) {
allKeys = union(allKeys, Object.keys(obj));
}
allKeys.forEach(key => {
if (key.toLowerCase().includes("coroutine")) return;
if (softReset && root && key == "settings") return;
if (softReset && root && key == "cheats") return;
if (softReset && key == "simulationResetCount") return;
if (softReset && key == "remainingTime") return;
if (!root && obj[key] && obj[key].constructor == Object) {
Vue.set(obj, key, {});
}
if (source[key] && source[key].constructor == Object) {
if (!obj[key]) Vue.set(obj, key, {});
customMerge(obj[key], source[key], false, softReset);
}
else if (Array.isArray(source[key])) {
Vue.set(obj, key, []);
for (let i = 0; i < source[key].length; i++) {
Vue.set(obj[key], i, source[key][i]);
}
}
else {
if (root && !source[key]) return;
Vue.set(obj, key, source[key]);
}
});
}
Example #2
Source File: node-details-table.js From ThreatMapper with Apache License 2.0 | 6 votes |
function getNodeValue(node, header) {
const fieldId = header && header.id;
if (fieldId !== null) {
let field = union(node.metrics, node.metadata).find(f => f.id === fieldId);
if (field) {
if (isIP(header)) {
// Format the IPs so that they are sorted numerically.
return ipToPaddedString(field.value);
} if (isNumeric(header)) {
return parseFloat(field.value);
}
return field.value;
}
if (node.parents) {
field = node.parents.find(f => f.topologyId === fieldId);
if (field) {
return field.label;
}
}
if (node[fieldId] !== undefined && node[fieldId] !== null) {
return node[fieldId];
}
}
return null;
}
Example #3
Source File: node-details-table.js From ThreatMapper with Apache License 2.0 | 6 votes |
function getNodeValue(node, header) {
const fieldId = header && header.id;
if (fieldId !== null) {
let field = union(node.metrics, node.metadata).find(f => f.id === fieldId);
if (field) {
if (isIP(header)) {
// Format the IPs so that they are sorted numerically.
return ipToPaddedString(field.value);
} if (isNumber(header)) {
return parseFloat(field.value);
}
return field.value;
}
if (node.parents) {
field = node.parents.find(f => f.topologyId === fieldId);
if (field) {
return field.label;
}
}
if (node[fieldId] !== undefined && node[fieldId] !== null) {
return node[fieldId];
}
}
return null;
}
Example #4
Source File: index.js From datapass with GNU Affero General Public License v3.0 | 5 votes |
MultiSelect = ({
options = [],
values = [],
disabled = false,
onChange,
}) => {
const [isContentOpen, setIsContentOpen] = useState(false);
const handleButtonClick = () => {
setIsContentOpen(!isContentOpen);
};
const handleOutsideClick = () => {
setIsContentOpen(false);
};
const handleChange = (event) => {
const {
target: { name, checked },
} = event;
let newValues = checked ? union(values, [name]) : xor(values, [name]);
onChange(newValues);
};
let overviewLabel;
if (values.length === 0) {
overviewLabel = 'Tous';
} else if (values.length === 1) {
overviewLabel = options.find(({ key }) => key === values[0])?.label;
} else {
overviewLabel = `${values.length} sélections`;
}
return (
<div>
<div className="multiselect-dropdown-button" onClick={handleButtonClick}>
{overviewLabel}
</div>
{isContentOpen && (
<Dropdown onOutsideClick={handleOutsideClick}>
<FieldsetWrapper small>
{options.map(({ key, label }) => (
<div key={key}>
<CheckboxInput
name={key}
label={label}
onChange={handleChange}
value={values.includes(key)}
disabled={disabled}
/>
</div>
))}
</FieldsetWrapper>
</Dropdown>
)}
</div>
);
}