本文整理汇总了TypeScript中ramda.mergeDeepRight函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mergeDeepRight函数的具体用法?TypeScript mergeDeepRight怎么用?TypeScript mergeDeepRight使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mergeDeepRight函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: castModelKey
export const hiddenComponentDecorator = ({
modelName,
fields,
}: {
modelName: string;
fields: Fields;
}): { modelName; fields: Fields & WithHidden } => {
const TAG = '[hiddenComponentDecorator]';
logger.log(TAG, { fields });
let wrappedFields = R.omit([castModelKey('createdAt'), castModelKey('updatedAt')])(fields);
if (R.has('id', wrappedFields)) {
const hidden = R.isNil(wrappedFields.id.value);
wrappedFields = R.mergeDeepRight(wrappedFields, { id: { options: { hidden } } });
}
const positions = R.filter(R.pathEq(['options', 'type'], 'SortPosition'))(wrappedFields);
if (!R.isEmpty(positions)) {
const hiddenPositions = R.map(position => ({
...position,
options: { hidden: true },
}))(positions);
wrappedFields = R.mergeDeepRight(wrappedFields, { ...hiddenPositions });
}
logger.log(TAG, 'wrappedFields', { wrappedFields }, diff(fields, wrappedFields));
return { modelName, fields: wrappedFields };
};
示例2: wrapForeignOpt
export const associationDecorator = ({ modelName, fields }: { modelName: string; fields }) => {
const TAG = '[associationDecorator]';
logger.log(TAG, { fields });
// prettier-ignore
const associationFields = R.filter(R.compose(R.not, R.isNil, R.prop('associations')))(fields);
logger.log(TAG, { associationFields }, R.not(R.isEmpty(associationFields)));
if (R.not(R.isEmpty(associationFields))) {
const wrapForeignOpt = R.map(opt => ({
...opt,
association: AppContext.adapters.models.getAssociationConfigs(opt.modelName),
}));
const withAssociations = R.mapObjIndexed(field => ({
...field,
foreignOpts: wrapForeignOpt(field.foreignOpts),
}))(associationFields);
logger.debug(TAG, { withAssociations, wrapForeignOpt });
const wrappedFields = R.mergeDeepRight(fields, withAssociations);
logger.debug(TAG, { wrappedFields });
return { modelName, fields: wrappedFields };
}
return { modelName, fields };
};
示例3: default
export default (options: ThemeOptions) =>
createMuiTheme(
mergeDeepRight(
themeDefaults({
spacing: spacingStorage.get()
}),
options
)
);
示例4: adoptDataToHost
Object.keys(nodeMap).forEach(contextPath => {
// This data may be coming from the Guest frame, so we need to re-create it at host/
// Otherwise we get all "can't execute code from a freed script" errors in Edge,
// when the guest frame has been navigated away and old guest frame document was destroyed
const newNode = adoptDataToHost(nodeMap[contextPath]);
if (!newNode) {
throw new Error('This error should never be thrown, it\'s a way to fool TypeScript');
}
const mergedNode = mergeDeepRight(draft.byContextPath[contextPath], newNode);
// Force overwrite of children
if (newNode.children !== undefined) {
mergedNode.children = newNode.children;
}
// Force overwrite of matchesCurrentDimensions
if (newNode.matchesCurrentDimensions !== undefined) {
mergedNode.matchesCurrentDimensions = newNode.matchesCurrentDimensions;
}
draft.byContextPath[contextPath] = mergedNode;
});
示例5: catch
export const jsonDecorator = ({
modelName,
fields,
}: {
modelName: string;
fields: (Fields & WithHidden) | PositionsField;
}): { modelName; fields: (Fields & WithHidden) | PositionsField } => {
const TAG = '[jsonDecorator]';
logger.log(TAG, { fields });
const jsonFields = R.filter(R.pathEq(['options', 'json'], 'str'))(fields);
if (R.not(R.isEmpty(jsonFields))) {
logger.debug(TAG, { jsonFields });
const toJson = value => {
if (R.is(String, value) && value.length) {
try {
return JSON.parse(value);
} catch (e) {
logger.warn(TAG, e, { jsonFields });
return null;
}
}
if (R.is(Object, value)) {
return value;
}
return null;
};
const transformValue = R.over(R.lens(R.prop('value'), R.assoc('value')), toJson);
const transformedFields = R.map(transformValue)(jsonFields);
const wrappedFields = R.mergeDeepRight(fields, transformedFields);
logger.log(TAG, 'wrappedFields', { wrappedFields });
return { modelName, fields: wrappedFields };
}
return { modelName, fields };
};
示例6: diff
export const dynamicTypeDecorator = ({
modelName,
fields,
}: {
modelName: string;
fields: Fields;
}): { modelName; fields: Fields } => {
const TAG = '[dynamicTypeDecorator]';
const { columns } = AppContext.ctx.models.getModelConfig(modelName);
logger.log(TAG, { fields, columns });
const typePairs = Object.assign(
{},
..._.map(columns, (column, key) => ({ [key]: { type: column.editor(fields) } })),
);
logger.log(TAG, { typePairs });
const wrappedFields = R.mergeDeepRight(fields, typePairs);
logger.log(TAG, { wrappedFields }, diff(fields, wrappedFields));
return { modelName, fields: wrappedFields };
};
示例7:
const menuReducer = (previousState = initialState, action) => {
if (isMenuModule(action)) {
return R.mergeDeepRight(previousState, action.payload);
}
return previousState;
};
示例8:
const securityReducer = (previousState = initialState, action) => {
if (isSecurityModule(action)) {
return R.mergeDeepRight(previousState, action.payload);
}
return previousState;
};
示例9: require
versionCode,
dependencies: { expo }
} = require('../package.json');
const isDev = process.argv[2] === 'development';
const expoVersion = expo.replace('^', '');
const sdkVersion = `${semver.major(expoVersion)}.0.0`;
const travisConfig = mergeDeepRight(config, {
expo: {
name: `${config.expo.name}${isDev ? ' Nightly' : ''}`,
slug: `${config.expo.slug}${isDev ? '-development' : ''}`,
sdkVersion,
version,
packagerOpts: {
nonPersistent: true
},
ios: {
buildNumber: version.split('-')[0]
},
android: {
versionCode
}
}
});
fs.writeFileSync(
path.join(__dirname, '..', 'app.travis.json'),
JSON.stringify(travisConfig, undefined, 2)
);
示例10: produce
export const reducer = (state: State = defaultState, action: InitAction | Action) => produce(state, draft => {
switch (action.type) {
case system.INIT: {
draft.byContextPath = action.payload.cr.nodes.byContextPath;
draft.documentNode = action.payload.cr.nodes.documentNode;
draft.siteNode = action.payload.cr.nodes.siteNode;
draft.clipboard = action.payload.cr.nodes.clipboard;
draft.clipboardMode = action.payload.cr.nodes.clipboardMode;
break;
}
case actionTypes.ADD: {
const {nodeMap} = action.payload;
Object.keys(nodeMap).forEach(contextPath => {
draft.byContextPath[contextPath] = adoptDataToHost(nodeMap[contextPath]);
});
break;
}
case actionTypes.CHANGE_PROPERTY: {
const {propertyChanges} = action.payload;
propertyChanges.forEach(propertyChange => {
const node = getNodeOrThrow(draft.byContextPath, propertyChange.subject);
node.properties[propertyChange.propertyName] = propertyChange.value;
});
break;
}
case actionTypes.MOVE: {
const {nodeToBeMoved: sourceNodeContextPath, targetNode: targetNodeContextPath, position} = action.payload;
let baseNodeContextPath;
if (position === 'into') {
baseNodeContextPath = targetNodeContextPath;
} else {
baseNodeContextPath = parentNodeContextPath(targetNodeContextPath);
if (baseNodeContextPath === null) {
throw new Error(`Target node "{targetNodeContextPath}" doesn't have a parent, yet you are trying to move a node next to it`);
}
}
const sourceNodeParentContextPath = parentNodeContextPath(sourceNodeContextPath);
if (sourceNodeParentContextPath === null) {
throw new Error(`The source node "{sourceNodeParentContextPath}" doesn't have a parent, you can't move it`);
}
const baseNode = getNodeOrThrow(draft.byContextPath, baseNodeContextPath);
const sourceNodeParent = getNodeOrThrow(draft.byContextPath, sourceNodeParentContextPath);
const originalSourceChildren = sourceNodeParent.children;
const sourceIndex = originalSourceChildren.findIndex(child => child.contextPath === sourceNodeContextPath);
const childRepresentationOfSourceNode = originalSourceChildren[sourceIndex];
const processedChildren = baseNode.children;
if (sourceNodeParentContextPath === baseNodeContextPath) {
// If moving into the same parent, delete source node from it
processedChildren.splice(sourceIndex, 1);
} else {
// Else delete the source node from its parent
originalSourceChildren.splice(sourceIndex, 1);
sourceNodeParent.children = originalSourceChildren;
}
// Add source node to the children of the base node, at the right position
if (position === 'into') {
processedChildren.push(childRepresentationOfSourceNode);
} else {
const targetIndex = processedChildren.findIndex(child => child.contextPath === targetNodeContextPath);
const insertIndex = position === 'before' ? targetIndex : targetIndex + 1;
processedChildren.splice(insertIndex, 0, childRepresentationOfSourceNode);
}
baseNode.children = processedChildren;
break;
}
case actionTypes.MERGE: {
const {nodeMap} = action.payload;
Object.keys(nodeMap).forEach(contextPath => {
// This data may be coming from the Guest frame, so we need to re-create it at host/
// Otherwise we get all "can't execute code from a freed script" errors in Edge,
// when the guest frame has been navigated away and old guest frame document was destroyed
const newNode = adoptDataToHost(nodeMap[contextPath]);
if (!newNode) {
throw new Error('This error should never be thrown, it\'s a way to fool TypeScript');
}
const mergedNode = mergeDeepRight(draft.byContextPath[contextPath], newNode);
// Force overwrite of children
if (newNode.children !== undefined) {
mergedNode.children = newNode.children;
}
// Force overwrite of matchesCurrentDimensions
if (newNode.matchesCurrentDimensions !== undefined) {
mergedNode.matchesCurrentDimensions = newNode.matchesCurrentDimensions;
}
draft.byContextPath[contextPath] = mergedNode;
});
break;
}
case actionTypes.FOCUS: {
const {contextPath, fusionPath} = action.payload;
draft.focused.contextPath = contextPath;
draft.focused.fusionPath = fusionPath;
break;
}
//.........这里部分代码省略.........