hyper-react icon indicating copy to clipboard operation
hyper-react copied to clipboard

convert all return values to strings, unless?

Open catmando opened this issue 8 years ago • 5 comments

Why can't we just convert all values returned by the tag's block to a string?

If I say

li { foo }

and foo is for example a Time it fails.

catmando avatar Jan 30 '17 23:01 catmando

I am trying to reproduce the issue, but it seems like passing a Date as foo won't raise any exception. Would love to help if @fzingg could provide more information.

I am not sure about converting return values to string automatically, but at least we could make the exception raised more clear for debugging.

zetachang avatar Feb 04 '17 03:02 zetachang

@zetachang In fact it doesn't raise any exception for me as well but the value doesn't display at all without the to_s :

 td(width: '33%') { params.post.posttitle }
 td(width: '33%') { params.post.description }
 td(width: '33%') { params.post.created_at.to_s }

Here Posttile and description are displayed but created_at only displayed with to_s created_at is a timestamp here but I tried with date and I have the same issue.

I pushed it on a repo : https://github.com/fzingg/hyperloop-eventsapp

fzingg avatar Feb 04 '17 17:02 fzingg

@fzingg , thanks for updating the information. Does a exception like the following help?

Exception raised while rendering #<MyComponent:0x203c>: 
Instead of String or React::Element, a Time object was returned in one of child building block.

zetachang avatar Feb 05 '17 11:02 zetachang

Yes, I think it would be great.

fzingg avatar Feb 07 '17 10:02 fzingg

Note the better error message will be in Hyper-React 0.12, plus in Hyper-Component there will also be automatic conversion for the most common types, via the acts_as_string? flag

catmando avatar Mar 07 '17 02:03 catmando