Yoast / YoastSEO.js

Analyze content on a page and give SEO feedback as well as render a snippet preview.
GNU General Public License v3.0
403 stars 170 forks source link

Add visualization of the tree to the example #2122

Closed atimmer closed 5 years ago

atimmer commented 5 years ago

To be able to properly develop the tree and debug it if necessary, the tree needs to be visualized in the example.

The easiest way to implement this is to do these steps:

  1. Send the tree to the main thread. (Needs to be build)
  2. Transform the tree into JSON. (I think @hansjovis had already build a utility for this)
  3. Put this JSON into react-json-view: https://www.npmjs.com/package/react-json-view. Note: If a node has a parent property this will cause a circular reference and this WILL crash your browser when using react-json-view.

The other way is to, which might result in a better visualization but is a ton more work:

  1. Send the tree to the main thread. (Needs to be build)
  2. Build React components for each node in the tree.

If you find a better visualization library that that can obviously also be used.

Parent #1903

hansjovis commented 5 years ago

I implemented a toString method on the Node class that calls JSON.stringify on the Node itself.

Note: If a node has a parent property this will cause a circular reference and this WILL crash your browser when using react-json-view.

It has a custom replacer that removes the parent parameter to remove circular dependencies, so this has been fixed 🙂. So calling JSON.parse on this stringified tree would get you a safe JSON representation.