Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// *** 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 });
function makeFirebaseState (action, state, path, value, merge = false) {
// const keyPath = urlToKeyPath(path)
// const dataPath = 'data.' + keyPath
const dataPath = ['data'].concat(splitUrl(path))
// const statusPath = 'status.' + keyPath
// debug('MAKE FIREBASE STATE FOR ACTION', action.type, 'VALUE', keyPath, value, 'merge', merge)
value = merge ? value : updeep.constant(value)
const newState = updeep.updateIn(dataPath, value, state)
return newState
}
obj.setIn = function(pathNodes, value) {
/*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;
if (deepObj[pathNode] == null) {
deepObj[pathNode] = {};
}
deepObj = deepObj[pathNode];
}
deepObj[pathNodes.slice(-1)[0]] = value;
return this;*/
//return u.updateIn(pathNodes.join("."), value, this);
return u.updateIn(pathNodes.join("."), u.constant(value), this);
};
function State(...args) {
let state = State_overrideData_path != null
? u.updateIn(State_overrideData_path.replace(/\//g, "."), u.constant(State_overrideData_value), store.getState())
: store.getState();
if (args.length == 0) return state;
let pathSegments: (string | number)[], options = new State_Options();
if (typeof args[0] == "object") {
[options, ...pathSegments] = args;
} else {
pathSegments = args;
}
if (typeof pathSegments[0] == "function") {
pathSegments = ConvertPathGetterFuncToPropChain(args[0]);
} else { //if (typeof pathSegments[0] == "string") {
if (pathSegments.length == 1) pathSegments = SplitStringBySlash_Cached(pathSegments[0] as string); // if only one string provided, assume it's the full path
}
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;
}
export function UpdateStateDataOverride(updates) {
Assert(State_overrideData_path != null, "Cannot update a state-data-override when none has been activated yet.");
for (let {name: path, value} of updates.Props()) {
State_overrideData_value = u.updateIn(path.replace(/\//g, "."), u.constant(value), State_overrideData_value);
}
}
export function StopStateDataOverride() {
function reduceReset(state) {
return u(
{
budgetsByPeriod: u.constant({})
},
state
);
}