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

Problem passing state data to js function in template #2866

Closed
2 of 7 tasks
chrisk314 opened this issue Jun 5, 2020 · 3 comments
Closed
2 of 7 tasks

Problem passing state data to js function in template #2866

chrisk314 opened this issue Jun 5, 2020 · 3 comments
Assignees

Comments

@chrisk314
Copy link
Contributor

Help us to manage our issues by answering the following:

  1. Describe your issue:

Hi there, I'm trying to do something which seems like it should be very straightforward. I'm attempting to pass some data to a javascript function in a riot template as below. In the Riot documentation it is stated that:

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

So I am expecting that the below should function correctly as it is valid javascript.

<date-test>

  <p>Test date string: { state.test }</p>
  <p>Test transformed literal date string: { (new Date('2006-09-16T00:00:00Z')).toLocaleDateString() }</p>
  <p>Test transformed date string: { (new Date(state.test)).toLocaleDateString() }</p>

  <script>
    export default {
      state: {
        test: '2006-09-16T00:00:00Z'
      }
    }
  </script>

</date-test>

The first two <p> tags are rendered correctly but with the last one I'm encountering the following error reported in Chrome dev console

Uncaught (in promise) ReferenceError: state is not defined

Please note that I am not experienced in javascript - I write python, c/c++ for my day job - so it's possible that I'm doing something which is clearly wrong... Any guidance as to the correct way to do this would be much appreciated.

  1. Can you reproduce the issue?

Post the link using one of our bug report templates:

  1. On which browser/OS does the issue appear?
    Ubuntu 20.04
    Chromium Version 83.0.4103.61 (Official Build) snap (64-bit)

  2. Which version of Riot does it affect?
    Riot.js 4.0.5

  3. How would you tag this issue?

  • Question
  • Bug (maybe...not sure...)
  • Discussion
  • Feature request
  • Tip
  • Enhancement
  • Performance
@GianlucaGuarini GianlucaGuarini self-assigned this Jun 5, 2020
@GianlucaGuarini
Copy link
Member

It's a compiler bug, I will check it asap

@GianlucaGuarini
Copy link
Member

Fixed in Riot.js@4.13.1

@chrisk314
Copy link
Contributor Author

Excellent. All working as expected. Thanks!

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