How to use the updeep.constant function in updeep

To help you get started, we’ve selected a few updeep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github substantial / updeep / types / tests.ts View on Github external
// *** 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 });
github AndersDJohnson / firedux / src / index.js View on Github external
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
    }
github Venryx / DebateMap / node_modules / react-redux-firebase / dist / reducer.js View on Github external
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);
	};
github Venryx / DebateMap / Source / Store / index.ts View on Github external
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
	}
github Venryx / DebateMap / Source / Frame / Database / DatabaseHelpers.ts View on Github external
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;
}
github Venryx / DebateMap / Source / UI / @Shared / StateOverrides.ts View on Github external
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() {
github kresusapp / kresus / client / store / budgets.js View on Github external
function reduceReset(state) {
    return u(
        {
            budgetsByPeriod: u.constant({})
        },
        state
    );
}

updeep

Easily update nested frozen objects and arrays in a declarative and immutable manner.

MIT
Latest version published 1 year ago

Package Health Score

60 / 100
Full package analysis