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

Extending a Riot.Element with templates #43

Open
andrewvarga opened this issue Jan 10, 2017 · 3 comments
Open

Extending a Riot.Element with templates #43

andrewvarga opened this issue Jan 10, 2017 · 3 comments

Comments

@andrewvarga
Copy link

Hi Nino,

this is not a bug, more like a question and it's probably related to riot more than riotTS.

I'm wondering if it's possible that if I have a class which has a template to extend that class but be able to use the parent's template too.
The closest I could get to this was to use composition instead of inheritance and <yield/>.

So something like this:

@template(`
   <mycomp>
      <p>mycomp content</p> 
      <yield/>
   </mycomp>
)
class MyComponent extends Riot.Element
{
    // ....
}

// This kinda does what I need (except that MyChild doesn't inherit from MyComp):
`@template(`
   <mychild>
      <mycomp>test</mycomp>
   </mychild>
)
class MyChild extends Riot.Element
{
    // ...
}

// This doesn't work, the template override MyComponent's template and I couldn't find a way to be able to use the parent's template
`@template(`
   <mychild>
      <div>test</div>
   </mychild>
)
class MyChild extends MyComponent
{
    // ...
 }

Or maybe I'm using a wrong approach and I shouldn't even try to do this?

@nippur72
Copy link
Owner

Yes @template is overridden because this is how classes are supposed to work. But perhaps in your case you just need to have a 3rd element which is a common ancestor for MyComp and MyChild, e.g.

class MyCommonBase extends Riot.Element { /*...*/ }
class MyComponent extends MyCommonBase { /*...*/ } 
class MyChild extends MyCommonBase { /*...*/ } 

(not sure what you want to achieve though)

@andrewvarga
Copy link
Author

Thank you that sounds reasonable. I just wanted to reuse the template of my parent class without having to rewrite it, but I will try to explain my use case better.

@sidouglas
Copy link

sidouglas commented Jan 12, 2017

I'll be interested to hear back from @andrewvarga to see if this is working as intended. This relates to issue 40

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

No branches or pull requests

3 participants