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
We could add a bit modified version of Spacebars.call which makes sure that all undefined values
are converted to null values. This makes it much easier to work with template inclusions {{> foobar}}which require inclusion to be a Blaze Template or null, but not undefined.
Additionally, if value is null or undefined, do not complain about not being a function.
This then works much more like CoffeeScript ?, so that {{foo.bar 'test'}} is more like {{foo?.bar? 'test'}} instead of failing if bar is not defined. In practice, this allows
us to do things like {{> this.lookup.renderEditor}} and {{editor.getValue 'foobar'}}
even if this or editor is undefined.
This is not a necessary change for Blaze Components to work. But it makes things really simpler sometimes.
Spacebars.call= (value) ->if_.isFunction value
# Evaluate arguments if they are functions (by calling them).newArgs= []
for i in [1...arguments.length]
arg=arguments[i]
newArgs.pushif_.isFunction(arg) thenarg() else arg
# Always return null instead of undefined.value.apply(null, newArgs) ?null# If value is not null or undefined, then return it as it is.elseif value?ifarguments.length>1thrownewError('Can\'t call non-function: '+ value)
value
# But if it is null or undefined, always return null instead.elsenull
The text was updated successfully, but these errors were encountered:
We could add a bit modified version of
Spacebars.call
which makes sure that all undefined valuesare converted to
null
values. This makes it much easier to work with template inclusions{{> foobar}}
which require inclusion to be a Blaze Template ornull
, but notundefined
.Additionally, if value is
null
orundefined
, do not complain about not being a function.This then works much more like CoffeeScript
?
, so that{{foo.bar 'test'}}
is more like{{foo?.bar? 'test'}}
instead of failing ifbar
is not defined. In practice, this allowsus to do things like
{{> this.lookup.renderEditor}}
and{{editor.getValue 'foobar'}}
even if
this
oreditor
isundefined
.See meteor/meteor#4230 and meteor/meteor#4232.
This is not a necessary change for Blaze Components to work. But it makes things really simpler sometimes.
The text was updated successfully, but these errors were encountered: