本文整理汇总了TypeScript中lodash.flow函数的典型用法代码示例。如果您正苦于以下问题:TypeScript flow函数的具体用法?TypeScript flow怎么用?TypeScript flow使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flow函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: connectBranchCommits
function connectBranchCommits(branchColor: string, line: GraphLine): GraphLine {
const branchPaths = flow<
GraphLine,
number[],
number[][],
number[],
number[][],
number[][]
>(
(cells) =>
cells.reduce(
(point, { value }, index) => {
if (value === GraphSymbol.Commit) point.push(index);
return point;
},
[] as number[],
),
(points) =>
points.map((point, index) => {
// Duplicate inner points so we can build path chunks.
// e.g [1, 2] => [[1, 2]] and [1, 2, 2, 3] => [[1, 2], [2, 3]]
const isAtTheEdge = index === 0 || index === points.length - 1;
return isAtTheEdge ? [point] : [point, point];
}),
flatten,
chunk(2),
(chunks) => chunks.filter((path) => path.length === 2),
)(line);
return line.map(
(cell, index) =>
branchPaths.some(isInBranchPath(index))
? { value: GraphSymbol.Branch, color: branchColor }
: cell,
);
}
示例2: omit
export const getReindexWarnings = (flatSettings: FlatSettings): ReindexWarning[] => {
const warnings = [
// No warnings yet for 8.0 -> 9.0
] as Array<[ReindexWarning, boolean]>;
return warnings.filter(([_, applies]) => applies).map(([warning, _]) => warning);
};
const removeUnsettableSettings = (settings: FlatSettings['settings']) =>
omit(settings, [
'index.uuid',
'index.blocks.write',
'index.creation_date',
'index.legacy',
'index.mapping.single_type',
'index.provided_name',
'index.routing.allocation.initial_recovery._id',
'index.version.created',
'index.version.upgraded',
]);
// Use `flow` to pipe the settings through each function.
const transformSettings = flow(removeUnsettableSettings);
const updateFixableMappings = (mappings: FlatSettings['mappings']) => {
// TODO: change type to _doc
return mappings;
};
const transformMappings = flow(updateFixableMappings);
示例3: CancellationTokenSource
return createObservable<T>(observer => {
const cts = new CancellationTokenSource();
method(cts.token).then(_.flow(_.bind(observer.next, observer), _.bind(observer.complete, observer)), _.bind(observer.error, observer));
return () => cts.cancel();
}).publishReplay(1).refCount();
示例4: function
descriptor: TypedPropertyDescriptor<SyncMethod>,
) => {
const originalMethod = descriptor.value as SyncMethod;
// Do not use arrow syntax here. Use a function expression in
// order to use the correct value of `this` in this method
// tslint:disable-next-line:only-arrow-functions
descriptor.value = function(...args: any[]) {
try {
const result = originalMethod.apply(this, args);
return result;
} catch (error) {
const transformedError = errorTransformer(error);
throw transformedError;
}
};
return descriptor;
};
return syncErrorHandlingDecorator;
};
// _.flow(f, g) = f â g
const zeroExErrorTransformer = _.flow(schemaErrorTransformer, contractCallErrorTransformer);
export const decorators = {
asyncZeroExErrorHandler: asyncErrorHandlerFactory(zeroExErrorTransformer),
syncZeroExErrorHandler: syncErrorHandlerFactory(zeroExErrorTransformer),
};
示例5: computeGraphMap
// Translate rendered data into CLI logic.
//
// This is necessary because rendered data are optimized for browsers.
// Rendering is a bit different in CLI since we don't have pixels.
// Thus, we should translate data to have "line-per-line" instructions.
function computeGraphMap(gitgraph: GitgraphCore): GraphMap {
const {
branchesPaths,
commits,
commitMessagesX,
} = gitgraph.getRenderedData();
const branchesColors = Array.from(branchesPaths).map(
([branch]) => branch.computedColor!,
);
const branchSpacing = gitgraph.template.branch.spacing;
const graphSize = xToIndex(commitMessagesX);
const openedBranches = [commits[0].x];
let graph: GraphMap = [];
commits.forEach((commit, index) => {
const graphLine = emptyLine();
// Commit message should always be at the end of the graph.
graphLine[graphLine.length - 1] = {
value: {
hash: commit.hashAbbrev,
message: commit.subject,
refs: commit.refs,
},
color: commit.style.color!,
};
graphLine[xToIndex(commit.x)] = {
value: GraphSymbol.Commit,
color: commit.style.color!,
};
const previousCommit = commits[index - 1];
const isFirstCommitOfNewBranch = !includes(openedBranches, commit.x);
if (isFirstCommitOfNewBranch) {
graph = graph.concat(openBranchLines(previousCommit, commit));
openedBranches.push(commit.x);
}
const isMergeCommit = commit.parents.length > 1;
if (isMergeCommit) {
graph = graph.concat(mergeBranchLines(previousCommit, commit));
}
graph.push(graphLine);
});
return flow<GraphMap, GraphMap, GraphMap, GraphMap>(
// Transpose the graph so columns => lines (easier to map).
unzip,
(transposedGraph) =>
transposedGraph.map((line, index) =>
connectBranchCommits(branchColorFor(index), line),
),
// Transpose again to return the proper graph.
unzip,
)(graph);
function xToIndex(x: number): number {
return (x / branchSpacing) * 2;
}
function emptyLine(): GraphLine {
return fill(Array(graphSize), { value: GraphSymbol.Empty, color: "" });
}
function openBranchLines(origin: Commit, target: Commit): GraphLine[] {
const start = xToIndex(origin.x) + 1;
const end = xToIndex(target.x);
return range(start, end).map((index) => {
const line = emptyLine();
line[index] = {
value: GraphSymbol.BranchOpen,
color: branchColorFor(end),
};
return line;
});
}
function mergeBranchLines(origin: Commit, target: Commit): GraphLine[] {
const start = xToIndex(origin.x) - 1;
const end = xToIndex(target.x);
return range(start, end, -1).map((index) => {
const line = emptyLine();
line[index] = {
value: GraphSymbol.BranchMerge,
color: branchColorFor(start),
};
return line;
});
}
function branchColorFor(branchCommitsIndex: number): string {
//.........这里部分代码省略.........
示例6: Error
if (result === null) {
throw new Error(`Could not parse action type "${type}"`);
}
return {
category: result[1] as string,
name: result[2] as string,
};
}
export const getActionType = (enterface: ActionInterface) =>
enterface.actionType;
export const getActionName = (enterface: ActionInterface) => enterface.name;
export const getActionCategory = _.flow(
getActionType,
parseActionType,
v => v.category
);
export const getActionCategoryToken = _.flow(
getActionCategory,
_.camelCase,
_.upperFirst
);
export const getActionEnumName = _.flow(
getActionCategoryToken,
v => `${v}ActionType`
);
export const getActionEnumPropName = _.flow(getActionName, _.snakeCase, v =>
v.toUpperCase()
);
export const getActionUnionName = _.flow(
示例7: removePreAndSuf
export function removePreAndSuf(value: string, prefix: string, suffix: string): string {
return _.flow([_.curry(removeSuffix)(_, suffix), _.curry(removePrefix)(_, prefix)])(value);
}
示例8:
public get editor$() {
if (!this._editor$) {
this._editor$ = _.flow(subscribeAsync, ensureEditor, cacheEditor)(this._source.observeActiveTextEditor());
}
return this._editor$;
}
示例9: flow
// Return false on empty Strings
if (isString(x) && isEmpty(trim(x, " \n"))) return false
// Intentional use of loose equality operator (Fogus)
return x != null // eslint-disable-line eqeqeq
}
// Coerce a usable value or nothing at all
export const existyValue = x => {
if (isExisty(x)) return x
}
export const capitalizeFirstCharacter = x =>
x.charAt(0).toUpperCase() + x.slice(1)
export const classify = flow(camelCase, capitalizeFirstCharacter)
export const join = (by, xs) => compact(xs).join(by)
export const truncate = (string, length, append = "âŚ") => {
const x = string + ""
const limit = ~~length
return x.length > limit ? x.slice(0, limit) + append : x
}
export const toQueryString = (options = {}) =>
stringify(options, {
arrayFormat: "brackets",
sort: (a, b) => a.localeCompare(b),
})
export const toKey = (path, options = {}) => `${path}?${toQueryString(options)}`
export const exclude = (values?: any[], property?: any) => xs =>