本文整理汇总了TypeScript中immutable-assign类的典型用法代码示例。如果您正苦于以下问题:TypeScript immutable-assign类的具体用法?TypeScript immutable-assign怎么用?TypeScript immutable-assign使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了immutable-assign类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hl
const pathwayCommentStream = hl(cxmlSources["/Pathway/Comment"]).map(function(
Comment
) {
processor.output = iassign(
processor.output,
function(o) {
return o.pathway;
},
function(pathway) {
const comments = pathway.comments || [];
comments.push(processProperties(Comment) as any);
pathway.comments = comments;
return pathway;
}
);
return processor.output;
});
示例2: iassign
.map(function(publicationXrefs: PvjsonPublicationXref[]) {
// TODO should these go through the processor instead?
processor.output = iassign(
processor.output,
function(o) {
return o.entitiesById;
},
function(entitiesById) {
publicationXrefs.forEach(function(publicationXref) {
entitiesById[publicationXref.id] = publicationXref;
});
return entitiesById;
}
);
return processor.output;
});
示例3: Error
.map(function(
groupedEntities: (PvjsonSingleFreeNode | PvjsonEdge)[]
): PvjsonGroup {
const pvjsonGroup = postprocessGroupPVJSON(
groupedEntities,
pvjsonEntity
);
const graphIdToZIndex = processor.graphIdToZIndex;
pvjsonGroup.contains = sortBy(
[
function(thisEntityId) {
return graphIdToZIndex[thisEntityId];
}
],
groupedEntities.map(x => x.id)
);
const { id, x, y } = pvjsonGroup;
const groupedEntitiesFinal = groupedEntities.map(function(
groupedEntity
) {
if (isPvjsonEdge(groupedEntity)) {
groupedEntity.points = map(function(point) {
point.x -= x;
point.y -= y;
return point;
}, groupedEntity.points);
} else if (isPvjsonSingleFreeNode(groupedEntity)) {
groupedEntity.height;
groupedEntity.x -= x;
groupedEntity.y -= y;
} else {
return hl.fromError(
new Error(
`
Encountered unexpected entity
${JSON.stringify(groupedEntity, null, " ")}
in Group
${JSON.stringify(pvjsonGroup, null, " ")}
`
)
);
}
// NOTE: this is needed for GPML2013a, because GPML2013a uses both
// GroupId/GroupRef and GraphId/GraphRef. GPML2017 uses a single
// identifier per entity. That identifier can be referenced by
// GroupRef and/or GraphRef. Pvjson follows GPML2017 in this, so
// we convert from GPML2013a format:
// GroupRef="GROUP_ID_VALUE"
// to pvjson format:
// {isPartOf: "GRAPH_ID_VALUE"}
groupedEntity.isPartOf = id;
return omit(["groupRef"], groupedEntity);
});
groupedEntitiesFinal.forEach(function(pvjsonEntity) {
setPvjsonEntity(pvjsonEntity);
});
setPvjsonEntity(pvjsonGroup);
processor.output = iassign(
processor.output,
function(o) {
return o.pathway.contains;
},
function(contains) {
return insertEntityIdAndSortByZIndex(
difference(contains, groupedEntitiesFinal.map(x => x["id"])),
id
);
}
);
return pvjsonGroup;
})
示例4: VError
.flatMap(function(
pvjsonEntity: PvjsonNode | PvjsonEdge
): Highland.Stream<
| {
pathway: Pathway | PathwayStarter;
entitiesById: PvjsonEntitiesById;
}
| Error
> {
const { id, zIndex } = pvjsonEntity;
// TODO we might want to sort by other criteria, such as
// to order a State above its DataNode, which would be
// ordered above its Group, if any
const insertEntityIdAndSortByZIndex = flow([
insertIfNotExists(id),
sortByZIndex
]);
let finalSortedStream;
if (isPvjsonEdgeOrBurr(pvjsonEntity)) {
const isAttachedTo = pvjsonEntity.isAttachedTo;
arrayify(isAttachedTo).forEach(function(graphRef: string) {
const graphRefs = graphIdsByGraphRef[graphRef] || [];
if (graphRefs.indexOf(id) === -1) {
graphRefs.push(id);
}
graphIdsByGraphRef[graphRef] = graphRefs;
});
if (isPvjsonBurr(pvjsonEntity)) {
finalSortedStream = hl(
getPvjsonEntityLatestByGraphId(isAttachedTo)
).map(function(
referencedEntity: PvjsonSingleFreeNode | PvjsonGroup | PvjsonEdge
) {
if (isPvjsonNode(referencedEntity)) {
const { attachmentDisplay } = pvjsonEntity;
const [
relativeOffsetScalarX,
relativeOffsetScalarY
] = attachmentDisplay.relativeOffset;
attachmentDisplay.offset = [
relativeOffsetScalarX * referencedEntity.width,
relativeOffsetScalarY * referencedEntity.height
];
pvjsonEntity.attachmentDisplay = omit(
["relativeOffset"],
attachmentDisplay
);
}
setPvjsonEntity(pvjsonEntity);
// NOTE: burrs are not added to the property "contained".
// Rather, they are added to the property "burrs".
referencedEntity.burrs = referencedEntity.burrs || [];
insertEntityIdAndSortByZIndex(referencedEntity.burrs);
setPvjsonEntity(referencedEntity);
return processor.output;
});
} else if (isPvjsonEdge(pvjsonEntity)) {
try {
const pvjsonEdge = postprocessEdgePVJSON(
processor.output.entitiesById as {
[key: string]: PvjsonNode | PvjsonEdge;
},
pvjsonEntity
);
processor.output = iassign(
processor.output,
function(o) {
return o.pathway.contains;
},
insertEntityIdAndSortByZIndex
);
setPvjsonEntity(pvjsonEdge);
finalSortedStream = hl([processor.output]);
} catch (err) {
return hl.fromError(err);
}
} else {
return hl.fromError(
new VError(
`
Unexpected entity type.
Only Edge or Burr should return true for
isPvjsonEdgeOrBurr(
${JSON.stringify(pvjsonEntity, null, " ")}
)
`
)
);
}
} else if (isPvjsonGroup(pvjsonEntity)) {
// We still have some GPML files with empty Groups and/or nested Groups
// floating around, but we don't process them, because that's a
// curation issue, not a gpml2pvjson issue.
//.........这里部分代码省略.........
示例5: assign
.map(function(metadata: Record<string, any>) {
processor.output = iassign(
processor.output,
function(o) {
return o.pathway;
},
function(pathway): Pathway {
const mergedPathway = assign(pathway, metadata);
// NOTE: GPML schema specifies that name is required
const { name } = mergedPathway;
const splitName = name.split(" (");
if (
!!splitName &&
splitName.length === 2 &&
!!name.match(/\(/g) &&
name.match(/\(/g).length === 1 &&
!!name.match(/\)/g) &&
name.match(/\)/g).length === 1
) {
mergedPathway.standardName = splitName[0];
mergedPathway.displayName = splitName[1].replace(")", "");
} else {
mergedPathway.standardName = name;
mergedPathway.displayName = name;
}
const stringifyKeyValueForPathway = stringifyKeyValue(mergedPathway);
mergedPathway.textContent = compact([
stringifyKeyValueForPathway("name"),
stringifyKeyValueForPathway("license"),
stringifyKeyValueForPathway("lastModified"),
stringifyKeyValueForPathway("organism")
]).join("\n");
const context: (string | Record<string, any>)[] = [
"https://cdn.rawgit.com/wikipathways/WpVocabularies/7a46a05/contexts/pvjs.jsonld"
];
if (!!mergedPathway.id) {
context.push({
"@base": mergedPathway.id + "/"
});
} else {
// If there's no pathway IRI specified, we at least give the user a URL
// to search WikiPathways. This way, the user at least has a chance of
// to search WikiPathways to possibly find the source for this data.
// NOTE: GPML schema specifies that organism is optional
const organismIriComponent = mergedPathway.hasOwnProperty(
"organism"
)
? `&species=${mergedPathway.organism}`
: "";
mergedPathway.isSimilarTo = encodeURI(
`http://wikipathways.org/index.php/Special:SearchPathways?query=${name}${organismIriComponent}&doSearch=1`
);
}
return assign(
{
"@context": context
},
mergedPathway
) as Pathway;
}
);
return processor.output;
})
示例6: toPvjson
export function toPvjson(
inputStreamWithMessedUpRDFIDs: NodeJS.ReadableStream,
pathwayIri?: string
) {
// NOTE: GPML2013a incorrectly uses "rdf:id" instead of "rdf:ID".
// We need to fix this error so that CXML can process the GPML.
const inputStream = hl(inputStreamWithMessedUpRDFIDs)
.splitBy(' rdf:id="')
.intersperse(' rdf:ID="');
const selectorToCXML = {
// TODO why does TS require that we use the Pathway's "constructor.prototype"
// instead of just the Pathway?
// Why does Pathway.Graphics not need that?
// Why do many of the other require using the prototype?
//
"/Pathway/@*": GPML2013a.document.Pathway.constructor.prototype,
"/Pathway/Comment": GPML2013a.document.Pathway.Comment[0],
"/Pathway/Graphics/@*": GPML2013a.document.Pathway.Graphics,
"/Pathway/DataNode": GPML2013a.DataNodeType.prototype,
"/Pathway/State": GPML2013a.StateType.prototype,
"/Pathway/Interaction": GPML2013a.InteractionType.prototype,
"/Pathway/GraphicalLine": GPML2013a.GraphicalLineType.prototype,
"/Pathway/Label": GPML2013a.LabelType.prototype,
"/Pathway/Shape": GPML2013a.ShapeType.prototype,
"/Pathway/Group": GPML2013a.GroupType.prototype,
"/Pathway/InfoBox": GPML2013a.InfoBoxType.prototype,
"/Pathway/Legend": GPML2013a.LegendType.prototype,
"/Pathway/Biopax/bp:PublicationXref":
GPML2013a.document.Pathway.Biopax.PublicationXref[0],
"/Pathway/Biopax/bp:openControlledVocabulary":
GPML2013a.document.Pathway.Biopax.openControlledVocabulary[0]
};
const cxmlXPath = new CXMLXPath(inputStream, GPML2013a, {
bp: "http://www.biopax.org/release/biopax-level3.owl#"
//rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
});
const cxmlSources = cxmlXPath.parse(selectorToCXML);
const processor = new Processor(
GPML2013aKeyMappings,
GPML2013aKeyValueMappings,
GPML2013aValueMappings,
GPML2013aValueConverters
);
const {
fillInGPMLPropertiesFromParent,
getPvjsonEntityLatestByGraphId,
graphIdsByGraphRef,
graphIdToZIndex,
getGPMLElementByGraphId,
preprocessGPMLElement,
processGPMLAndPropertiesAndType,
processProperties,
processPropertiesAndType,
setPvjsonEntity
} = processor;
if (pathwayIri) {
processor.output = iassign(
processor.output,
function(o) {
return o.pathway;
},
function(pathway) {
pathway.id = pathwayIri;
return pathway;
}
);
}
const sortByZIndex = sortByMap(graphIdToZIndex);
const pathwayMetadataStream = hl([
cxmlSources["/Pathway/@*"].doto(function(pathway) {
if (supportedNamespaces.indexOf(pathway._namespace) === -1) {
// TODO should we do anything further?
throw new Error(`Unsupported namespace: ${pathway._namespace}`);
}
}),
cxmlSources["/Pathway/Graphics/@*"]
])
.merge()
.map(processProperties)
.reduce({} as Record<string, any>, function(acc, metadataChunk) {
return assign(acc, metadataChunk);
})
// there should only be one item through this last step
.map(function(metadata: Record<string, any>) {
processor.output = iassign(
processor.output,
function(o) {
return o.pathway;
},
function(pathway): Pathway {
const mergedPathway = assign(pathway, metadata);
// NOTE: GPML schema specifies that name is required
const { name } = mergedPathway;
//.........这里部分代码省略.........