This repository has been archived by the owner on May 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display real type information in the State view instead of always "Ob…
…ject" (#776) * Display real type information in the State view instead of always "Object" * Remove MD5 reference (was used for path hashing) Object metadata cannot be based on paths, has to be based on reference, because the same object can appear at multiple paths - Luckily our serializer retains object references across serializations, so this can work for us * Separate object metadata and component metadata into separate maps. We cannot store component metadata keyed off values, because oftentimes those values are scalars that are not unique keys that can be used in a map. So now we store the component instance as the map key and then retain a list of all properties and their metadata.
- Loading branch information
Showing
13 changed files
with
131 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import {Path} from '../tree'; | ||
|
||
export type Apply = (path: Path, value) => void; | ||
import {isScalar} from './scalar'; | ||
|
||
export const recurse = (initialPath: Path, object, exec: Apply) => { | ||
export type Apply = (value) => void; | ||
|
||
// Recursive traversal of an object tree, but will not traverse circular references or DOM elements | ||
export const recurse = (object, apply: Apply) => { | ||
const visited = new Set(); | ||
|
||
const apply = (path: Path, value, fn: Apply) => { | ||
if (value == null || visited.has(value)) { | ||
const visit = value => { | ||
if (value == null || isScalar(value) || /Element/.test(Object.prototype.toString.call(value))) { | ||
return; | ||
} | ||
|
||
if (visited.has(value)) { // circular loop | ||
return; | ||
} | ||
|
||
visited.add(value); | ||
|
||
fn(path, value); | ||
apply(value); | ||
|
||
if (Array.isArray(value) || value instanceof Set) { | ||
(<any>value).forEach((v, k) => apply(path.concat([k]), v, fn)); | ||
(<any>value).forEach((v, k) => visit(v)); | ||
} | ||
else if (value instanceof Map) { | ||
value.forEach((v, k) => apply(path.concat([k]), v, fn)); | ||
value.forEach((v, k) => visit(v)); | ||
} | ||
else { | ||
Object.keys(value).forEach(k => apply(path.concat([k]), value[k], fn)); | ||
Object.keys(value).forEach(k => visit(value[k])); | ||
} | ||
}; | ||
|
||
apply(initialPath, object, exec); | ||
visit(object); | ||
}; |
Oops, something went wrong.