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

sharing mixin (globally) #879

Closed
k33g opened this issue Jun 26, 2015 · 2 comments
Closed

sharing mixin (globally) #879

k33g opened this issue Jun 26, 2015 · 2 comments
Labels

Comments

@k33g
Copy link
Contributor

k33g commented Jun 26, 2015

I define a mixin. I want it to be shared between my components

riot.mixin("hello",{sayHello: function() {return "Hello World!";}})
riot.mount("hello-world");

and my component is like that:

<hello-world>
  <h1>{message}</h1>
  <script>
    this.on("mount", function() {
      this.message = this.mixin("hello").sayHello();
      this.update();
    }.bind(this))
  </script>
</hello-world>

then I get this error: Uncaught TypeError: Cannot read property 'sayHello' of undefined

if I change this.mixin("hello").sayHello(); by riot.mixin("hello").sayHello(); like that, then all is all right

<hello-world>
  <h1>{message}</h1>
  <script>
    this.on("mount", function() {
      this.message = riot.mixin("hello").sayHello();
      this.update();
    }.bind(this))
  </script>
</hello-world>

see the PR proposal #877 : #877

@cognitom
Copy link
Member

riot.mixin("hello").sayHello() doesn't make sense. Try this.

<hello-world>
  <h1>{message}</h1>
  <script>
    this.mixin("hello")
    this.on("mount", function() {
      this.message = this.sayHello();
      this.update();
    }.bind(this))
  </script>
</hello-world>

But this seems still something weird. See the example below. It works as the same.

riot.mixin('hello', {
  message: "Hello World!"
})
<hello-world>
  <h1>{ message }</h1>
  <script>
    this.mixin('hello')
  </script>
</hello-world>

@k33g
Copy link
Contributor Author

k33g commented Jun 26, 2015

@cognitom oups! OK, I understood :) Thank you very much for you patience

@k33g k33g closed this as completed Jun 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants