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

flatten array of models #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

betocantu93
Copy link

@betocantu93 betocantu93 commented Jan 30, 2020

Hello, great addon! We use it heavily at Prysmex

This PR is simple, just allow positional models params to be an array and flatten the array before creating the url, mostly to make it compatible with the new api of <LinkTo />

A whole new pattern opened to us... passing array of models instead of positionally passing models

So we went from simple classic:
/some/route/{type}/{id}

{{link-to "some.route" model.type model.id}}

To every model knowing how to go to their show like this.

export default class SomeModel extends Model {

  showRoutePath = "some.route";

  get showRouteSegments() {
     return [this.type, this.id]
  } 

  get showRoute() {
      return {
        route: this.showRoutePath,
        models: this.showRouteSegments
     }
   }
}

And consume in a very dynamic manner in templates like this

<LinkTo @route={{@model.showRoute.route}} @models={{@model.showRoute.models}} />

With this flattening now we can use

<SomeButtonComponent @link={{href-to @model.showRoute.route @model.showRoute.models}} />

@betocantu93
Copy link
Author

would be cool if this gets merged.... or support named arguments called model and models?

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 this pull request may close these issues.

1 participant