witheve / Eve

Better tools for thought

Home Page:http://witheve.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Silent error

wilk opened this issue · comments

Hi,

I got a silent error with the following code:

search @session
  student = [#student name]
  randomNum = floor[value: random[seed: 10] * 100]

bind @browser
  [#div text: "student: {{student.name}}"]

bind @view
  // here lies the error that is student.value instead of student.name
  [#value | value: "{{student.value}} {{randomNum}}"]

Nothing is displayed because of student.value.
I was expecting an error message somewhere, maybe just after the [#value] sentence, but nothing appeared.

Is it normal?

I'm using:

  • Eve 0.2.3
  • Chrome 55
  • Mac OS X 10.11.6

Follows the gist: https://gist.github.com/anonymous/3ad9d378d37bb8c25647d6260aaac024

Wilk,

Yeah, this is normal, but probably deserves some explanation. By using student.value, you're conditioning the block on student.value being available. If it's not, then the block simply will not run. It's the same as if you did this:

search @session
  student = [#student name value]
  randomNum = floor[value: random[seed: 10] * 100]

bind @browser
  [#div text: "student: {{student.name}}"]

bind @view
  // here lies the error that is student.value instead of student.name
  [#value | value: "{{value}} {{randomNum}}"]

Where instead of using student.value I'm searching explicitly for [#student name value]. The reason you can do both, is with the dot notation, you can write a condition for when there isn't a student.value to keep the block running:

search
  student = [#student name]
  value = if student.value then student.value
               else 0

bind @view
  [#value | value: "{{name}} {{value}}"]

This block says "search for all students with names. If they have a value, then use that. Otherwise, the value is 0."

@cmontella

Crystal clear, thank you!