本文整理匯總了TypeScript中slim-dom.diffNode函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript diffNode函數的具體用法?TypeScript diffNode怎麽用?TypeScript diffNode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了diffNode函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: prepDiff
const patchNodeAndDOM = (oldNode: SlimParentNode, newNode: SlimParentNode, mount: HTMLElement, map: NativeObjectMap) => {
const diffs = prepDiff(oldNode, diffNode(oldNode, newNode));
for (const mutation of diffs) {
map = patchDOM2(mutation, oldNode, mount, map);
oldNode = patchNode2(mutation, oldNode);
}
return { node: oldNode, map };
};
示例2: it
it(`can diff ${oldSource} against ${newSource}`, async () => {
const { graph: ag } = await loadModuleDependencyGraph("entry.pc", {
readFile: () => Promise.resolve(wrapSource(oldSource))
});
const { graph: bg } = await loadModuleDependencyGraph("entry.pc", {
readFile: () => Promise.resolve(wrapSource(newSource))
});
const { document: an } = runPCFile({ entry: {filePath: "entry.pc", componentId: "entry", previewName: "main" }, graph: ag });
const { document: bn, diagnostics } = runPCFile({ entry: {filePath: "entry.pc", componentId: "entry", previewName: "main" }, graph: bg });
const diffs = diffNode(an, bn);
expect(diffs).to.eql(expectedDiffs);
});
示例3: getComponentJSONPreviewDiff
function* getComponentJSONPreviewDiff(req: express.Request, res: express.Response, next) {
const state: ApplicationState = yield select();
const { componentId, previewName, oldChecksum, newChecksum } = req.params;
const oldDocument = getPreviewDocumentByChecksum(componentId, previewName, oldChecksum, state);
const newDocument = getPreviewDocumentByChecksum(componentId, previewName, newChecksum, state);
if (!oldDocument) {
return next();
}
if (!newDocument) {
return next();
}
return res.send(diffNode(oldDocument, newDocument));
}
示例4: evaluatePreviews
function* evaluatePreviews(graph: DependencyGraph, sourceUri: string) {
const state: ApplicationState = yield select();
const moduleSourceDirectory = getModuleSourceDirectory(state);
for (const filePath in graph) {
const dep = graph[filePath];
if (sourceUri && sourceUri !== filePath && values(dep.resolvedImportUris).indexOf(sourceUri) === -1) {
continue;
}
const { module } = dep;
if (module.type === PCModuleType.COMPONENT) {
for (const component of (module as ComponentModule).components) {
for (const preview of component.previews) {
const entry = {
componentId: component.id,
filePath,
previewName: preview.name
}
const { document } = runPCFile({ entry, graph, directoryAliases: {
// TODO - will eventually want to pass host and protocol information here too
[moduleSourceDirectory]: `http://localhost:${state.options.port}${PUBLIC_SRC_DIR_PATH}`
} });
const prevDocument = getLatestPreviewDocument(component.id, preview.name, yield select());
console.log(`Evaluated component ${component.id}:${preview.name}`);
let newDocument = document as SlimParentNode;
// TODO - push diagnostics too
yield put(previewEvaluated(component.id, preview.name, newDocument));
if (prevDocument) {
const diff = diffNode(prevDocument, newDocument);
// push even if there are no diffs so that FE can flag windows as loaded.
yield put(previewDiffed(component.id, preview.name, getDocumentChecksum(prevDocument), diff));
}
}
}
}
}
}