Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/specmap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SpecMap {
// We might consider making this (traversing & application) configurable later.
function createKeyBasedPlugin(pluginObj) {
return function* (patches, specmap) {
const traversedRefs = {}

for (const patch of patches.filter(lib.isAdditiveMutation)) {
yield* traverse(patch.value, patch.path, patch)
}
Expand All @@ -102,9 +104,21 @@ class SpecMap {
for (const key of Object.keys(obj)) {
const val = obj[key]
const updatedPath = path.concat(key)

if (lib.isObject(val)) {
yield* traverse(val, updatedPath, patch)
const isObj = lib.isObject(val)

// If the object has a meta '$$ref' - and store this $$ref
// in a lookaside to prevent future traversals of this $ref's tree.
const objRef = obj.$$ref
const traversed = specmap.allowMetaPatches && traversedRefs[obj.$$ref]

if (!traversed) {
if (isObj) {
// Only store the ref if it exists
if (specmap.allowMetaPatches && objRef) {
traversedRefs[objRef] = true
}
yield* traverse(val, updatedPath, patch)
}
}

if (!isRootProperties && key === pluginObj.key) {
Expand Down