You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to better error checking (#1518) we could make templates "smarter" and easier to use, taking error handling to these next levels:
make the directives handle undefined/null cases more elegantly
make the expressions null-check automatically
For the first level, EachBlock can check for null and treat it as an empty array. Attribute and text bindings can check for null and set an empty string instead of undefined
The second level makes it even easier. In my old framework each expression in the template was converted to a getter function that allowed no-ops for null errors. I took what CoffeeScript was doing to convert an expression with the existential operator on accessors like foo?.bar?.doit?() and making it standard in every expression. See https://github.com/chip-js/expressions-js. But I did it using regex (not ideal) instead of something better like Acorn. It would convert
And all the directives were coded to handle undefined so a simple text binding { user.name } would give an empty string if user or user.name were undefined or null. Makes is much more noob friendly and simplifies template code.
Upsides
less code needing being written for null checks
fewer breaking errors in your app once it goes to production
easier for Svelte noobs to get going if they don't have to worry about how the data will act, if the directives are resilient to whatever data they receive
Downsides
increased bundle size
users confused when their data isn't showing up because errors aren't popping
Perhaps there could be helpers in shared.js that would accomplish the same thing as the generated functions, similar to lodash's _.get(obj, 'prop.subprop').
As for users being confused, I think that will always be the case whatever you do. They can simply view the state of their data to see why it isn't showing.
The text was updated successfully, but these errors were encountered:
Related to better error checking (#1518) we could make templates "smarter" and easier to use, taking error handling to these next levels:
undefined
/null
cases more elegantlyFor the first level,
EachBlock
can check fornull
and treat it as an empty array. Attribute and text bindings can check fornull
and set an empty string instead ofundefined
The second level makes it even easier. In my old framework each expression in the template was converted to a getter function that allowed no-ops for null errors. I took what CoffeeScript was doing to convert an expression with the existential operator on accessors like
foo?.bar?.doit?()
and making it standard in every expression. See https://github.com/chip-js/expressions-js. But I did it using regex (not ideal) instead of something better like Acorn. It would convertto
And all the directives were coded to handle
undefined
so a simple text binding{ user.name }
would give an empty string ifuser
oruser.name
wereundefined
ornull
. Makes is much more noob friendly and simplifies template code.Upsides
Downsides
Perhaps there could be helpers in shared.js that would accomplish the same thing as the generated functions, similar to lodash's
_.get(obj, 'prop.subprop')
.As for users being confused, I think that will always be the case whatever you do. They can simply view the state of their data to see why it isn't showing.
The text was updated successfully, but these errors were encountered: