Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q: Dynamically rendering a label that is a function inside an object? #100

Closed
AnthonyClausing opened this issue Jul 20, 2020 · 1 comment · Fixed by #101
Closed

Q: Dynamically rendering a label that is a function inside an object? #100

AnthonyClausing opened this issue Jul 20, 2020 · 1 comment · Fixed by #101

Comments

@AnthonyClausing
Copy link

Hi, I'm trying to do something like this:

breadcrumb: {
  label: routeParams => `route params name: ${routeParams.name}` },
  parent: 'Menus'
}

But when I look at the getBreadcumb function I noticed to my understanding it is not possible:

getBreadcrumb(bc: string | CallbackFunction | Breadcrumbs): string {  
   let name = bc;
   if(typeof name === "object") {
     name = name.label
   }
   if (typeof name === "function") {
     return name.call(this, this.$route.params);
   }
  return name;
}

Is it possible for you to cover this feature in the future? I think replacing:

   if(typeof name === "object") {
     name = name.label
   }

with:

  if(typeof name === "object") {
     if(typeof name.label === 'function) {
       return name.label.call(this, this.$route.params);
     } else {
       name = name.label
     }
  }

Would work and wouldn't be a breaking change

@AnthonyClausing AnthonyClausing changed the title Dynamically rendering a label that is a function inside an object? Q: Dynamically rendering a label that is a function inside an object? Jul 20, 2020
Scrum added a commit that referenced this issue Jul 21, 2020
@Scrum
Copy link
Owner

Scrum commented Jul 21, 2020

@AnthonyClausing Thank you, but this is an oversight on my part. I originally planned to do the same as you suggest because I described it in the type.

type Breadcrumbs = {
label: string | CallbackFunction
parent: string
}

And I decided to do a little better. Now you can return dynamically an object

breadcrumb() {
  const { name } = this.$route;

  return {
    label: name,
    parent: 'settings'
  };
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants