Skip to content

Commit

Permalink
perf: don't recreate non-mutated context
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Oct 28, 2023
1 parent fb38a6d commit fb15661
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/entryhandler/keyword/EntryHandlerKeywordType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ export class EntryHandlerKeywordType extends EntryHandlerKeyword {
if (hasTypedScopedContext) {
// Do not propagate by default
scopedContext = scopedContext.then((c) => {
let rawContext = c.getContextRaw();

// Set the original context at this depth as a fallback
// This is needed when a context was already defined at the given depth,
// and this context needs to remain accessible from child nodes when propagation is disabled.
if (rawContext['@propagate'] !== true) {
rawContext = { ...rawContext, '@propagate': false, '@__propagateFallback': context.getContextRaw() };
if (c.getContextRaw()['@propagate'] !== true) {
return new JsonLdContextNormalized({ ...c.getContextRaw(), '@propagate': false, '@__propagateFallback': context.getContextRaw() });
}

return new JsonLdContextNormalized(rawContext);
return c;
});

// Set the new context in the context tree
Expand Down

0 comments on commit fb15661

Please sign in to comment.