ruidlopes / minimal.js

minimal.js: HTML+JSON template engine
172 stars 13 forks source link

minimal crashes if a key is missing from template #2

Closed dominictarr closed 13 years ago

dominictarr commented 13 years ago

this is a very cool project,

but playing around i found this problem:

if minimal can't find a html element, it type errors instead of ignoring it.

here is a gist: https://gist.github.com/852491

cheers.

ruidlopes commented 13 years ago

Thanks for using minimal.js and for reporting the issue.

Indeed, this is a known behaviour. I'm not sure if it should be a feature or a bug, though. Maybe raising an error and having developers handle the exception, or provide an option to turn on "silencing".

What do you think?

dominictarr commented 13 years ago

thanks for making this awesome module!

there may well be parts of the data you don't want to render, so the way I want to use this module I wouldn't want missing a rule to be an error at all.

then you can build up your view gradually and have more freedom to experiment without having to change the data coming in.

ruidlopes commented 13 years ago

I'm on the fence on this, which probably means having an optional parameter to fail silently vs. explicit exception. Your argument is sound, but more related to debugging and developing... I'll tinker something soon.

ruidlopes commented 13 years ago

fixed in the latest commit, with the following semantics: $m.exceptionHandler is executed when an element is not found. Default behaviour is function(){}.

Cheers Rui