wikitree / wikitree-dynamic-tree

Dynamically generated and browsed graphical family tree
MIT License
26 stars 20 forks source link

Update view handling in tree.js to support URL parameters #246

Closed harrislineage closed 1 month ago

harrislineage commented 2 months ago

View handling has been updated in tree.js to allow for passing additional parameters through the URL. The parameters are extracted from the URL, filtered based on what each view specifies in its meta().params, and then passed along when the view is initialized. This ensures that only parameters explicitly documented in the view's meta() are used, which keeps things clean and prevents unwanted data from being passed to views.

Within a view, parameters are defined and accepted in the view meta:

meta() {
   return {
      title: "MyNewView",
      description: `Mew view description`,
      docs: "https://www.WikiTree.com/wiki/Space:MyNewView",
      params: ["param1", "param2"]
   };
}

The parameters can then be used in the init:

init(selector, person_id, params) {
   console.log(params.param1);
   console.log(params.param2);
}