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

Expressions evaluation unclear/undocumented #2760

Closed
2 of 7 tasks
Gamadril opened this issue Sep 12, 2019 · 5 comments
Closed
2 of 7 tasks

Expressions evaluation unclear/undocumented #2760

Gamadril opened this issue Sep 12, 2019 · 5 comments
Assignees

Comments

@Gamadril
Copy link

Help us to manage our issues by answering the following:

  1. Describe your issue:
    It's totally unclear for me how expressions inside { } are evaluated. The documentation says:

All template expressions are “just javascript™️”: <pre>{ JSON.stringify(props) }</pre>

the example above works, but accessing other global variables not. Currently I cannot find a way to get { i18next.t('settings') } evaluated. In the generated code i18next is prefixed with "scope." So why "JSON.stringify" not? Isn't it also globally defined in window?

It would be easier for me as a developer to know in which cases "scope." is prefixed and in which not. And there should be a way (using special syntax maybe) to tell the compiler not to prefix the expressions (Feature Request).

  1. Can you reproduce the issue?

https://plnkr.co/edit/IQusfuupsQZueucRqjL8?p=preview

  1. On which browser/OS does the issue appear?
    All

  2. Which version of Riot does it affect?
    v4.5.0

  3. How would you tag this issue?

  • Question
  • Bug
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
@GianlucaGuarini
Copy link
Member

The proper way to render custom global variables in this case would be window.i18next.t('key'). While JSON is a known window/node global object i18next is not and that's why the Riot.js compiler doesn't know where to get this value. I will work on a patch ASAP. Thank you

@Gamadril
Copy link
Author

Actually "window." was the first thing I've tried, but it is still prefixed:
image

@GianlucaGuarini
Copy link
Member

@Gamadril that's the bug I will need to fix 😄 in the mean time something like this should be a bit cleaner and more elegant anyway

import i18next from 'i18next'

export default {
   i18next
}

@Gamadril
Copy link
Author

Thanks for the hint, I can live for now with the workaround 😄

@GianlucaGuarini
Copy link
Member

Fixed in Riot.js@4.5.1 thank you for reporting it

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

No branches or pull requests

2 participants