Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
u.ifElse(false as boolean, { a: 1 }, { a: 2 }, { a: 3 }); // $ExpectType object
u.ifElse(false as boolean, "foo", 3, { a: 3 }); // $ExpectType 3 | "foo"
u.ifElse(false, "foo", 3, { a: 3 }); // $ExpectType 3
u.ifElse(true, "foo", 3, { a: 3 }); // $ExpectType "foo"
// *** map ***
const inc = (i:number) => i+1;
u.map(inc, [1,2,3]); // $ExpectType number[]
u.map(inc, ["potato"]); // $ExpectType number[]
u.map({a:1},{a:2}); // $ExpectType Mapped<{ a: number; }, { a: number; }>
u.omit('bar', { }); // $ExpectType object
u.omit(['bar'], { }); // $ExpectType object
u.omitBy([ 'banana' ], { } ); // $ExpectError
// *** constant ***
// $ExpectType { banana: number; }
u.constant({ banana: 1 })('foo');
/// *** freeze ***
// $ExpectType { potato: number; }
u.freeze({ potato: 1 });
export function mapXYtoParam(state, action) {
const payload = action.payload;
// toggle: if already mapped to this then disconnect it
if (_.get(state, `xy.${payload.xy}.params.${payload.param}`)) {
return u(
{
mode: 'xy',
xy: {
[payload.xy]: {
// updeep: filter this param out of params
params: u.omit(payload.param)
}
}
},
state
);
}
// connect it
return u(
{
mode: 'xy',
xy: {
[payload.xy]: {
params: {
[payload.param]: true
}
function removeAccess(state, accessId) {
assert(
typeof accessId === 'number',
'The second parameter of removeAccess should be a number id'
);
// First remove all the accounts attached to the access.
let newState = state;
for (let accountId of accountIdsByAccessId(state, accessId)) {
newState = removeAccount(newState, accountId);
}
// Then remove access (should have been done by removeAccount).
newState = updateAccessesMap(newState, u.omit(accessId));
newState = u.updateIn('accessIds', u.reject(id => id === accessId), newState);
// Sort again accesses in case the default account has been deleted.
return sortAccesses(newState);
}
// Reset the defaultAccountId if we just deleted it.
if (getDefaultAccountId(newState) === accountId) {
newState = u({ defaultAccountId: DefaultSettings.get('default-account-id') }, newState);
}
// Reset the current account id if we just deleted it.
if (getCurrentAccountId(newState) === accountId) {
newState = setCurrentAccessAndAccount(newState);
}
// Remove alerts attached to the account.
newState = u.updateIn('alerts', u.reject(alert => alert.accountId === accountId), newState);
// Finally, remove the account from the accounts map.
return updateAccountsMap(newState, u.omit(accountId));
}
obj.deleteIn = function(pathNodes) {
/*var deepObj = this;
// tunnel down to the object holding the path-specified prop
for (var i in pathNodes.slice(0, -1)) {
var pathNode = pathNodes.slice(0, -1)[i];
if (deepObj == null) break;
deepObj = deepObj[pathNode];
}
delete deepObj[pathNodes.slice(-1)[0]];
return this;*/
//return u.updateIn(pathNodes.join("."), undefined, this);
return u.updateIn(pathNodes.slice(0, -1).join("."), u.omit(pathNodes.slice(-1)[0]), this);
};
}
export function ApplyDBUpdates_Local(dbData: FirebaseData, dbUpdates: Object) {
let result = dbData;
for (let {name: path, value} of dbUpdates.Props()) {
if (value != null) {
result = u.updateIn(path.replace(/\//g, "."), u.constant(value), result);
} else {
result = u.updateIn(path.split("/").slice(0, -1).join("."), u.omit(path.split("/").slice(-1)), result);
}
}
return result;
}
state);
}
case ActionTypes.CREATE_MESSAGE: {
return {
...state,
[action.message.id]: action.message
};
}
case ActionTypes.RECEIVE_RAW_CREATED_MESSAGE: {
let message = ChatMessageUtils.convertRawMessage(action.rawMessage);
message.isRead = true;
return compose(
u({[message.id]: message}),
u(u.omit(action.tempMessageID))
)(state);
}
case ActionTypes.RECEIVE_RAW_MESSAGES: {
let lastThreadID = last(action.rawMessages).threadID;
let messages = indexBy(action.rawMessages, 'id');
let formatMessage = u.map(message => u({
isRead: message.threadID === lastThreadID,
date: new Date(message.timestamp)
}, message));
let updated = u(formatMessage, messages);
return {...state, ...updated};
}
default:
return state;