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

Respond to null values #4

Open
premasagar opened this issue Mar 9, 2011 · 4 comments
Open

Respond to null values #4

premasagar opened this issue Mar 9, 2011 · 4 comments

Comments

@premasagar
Copy link
Owner

Currently, tim throws an exception that {{property}} not closed when it encounters a null value. This is because the typeof null === "object" and it is assuming this is an object.

Either nulls should be ignored, or the error message should be more clear.

@symroe
Copy link

symroe commented Oct 9, 2012

Hitting this with an API that I can't change....

Bit of a deal breaker for using tim for me. :(

Can you suggest a work around?

@premasagar
Copy link
Owner Author

Not tested, but it should be possible to add another else if at line 226:

else if (substituted === null){
    template = '';
}

This will return an empty string, instead of throwing an error.
Pull requests welcome ;)

@symroe
Copy link

symroe commented Oct 10, 2012

Not tested in tinytim (I guess this bug still applies?), and not minified (not sure what method you used for minifying).

@premasagar
Copy link
Owner Author

Great. Thanks @symroe.

I'm thinking that tinytim's block at line 47 should be changed to:

if (lookup === undef || lookup === null){
    return '';
}

So that it no longer throws an error if the property was not found. Throwing an error can be useful, for example, to catch problems in one's data-manipulation logic that may not be easily seen, but it is probably more hassle than it's worth.

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

No branches or pull requests

2 participants