These are chat archives for ractivejs/ractive

29th
Mar 2018
amadanmath
@amadanmath
Mar 29 2018 07:42
Hello... I'm back with another weird context question. playground throws TypeError: model.getKeypath is not a function. Take away .foo, and it works. Take away notokdatum definition, and it works. Bug or not bug?
( @evs-chris and @ceremcem helped me the last time see "not bug" )
Cerem Cem ASLAN
@ceremcem
Mar 29 2018 09:12
@brtu ...or try dot notation: Playground
Cerem Cem ASLAN
@ceremcem
Mar 29 2018 09:29
@amadanmath I think it work as you expect now: Playground
@evs-chris at this juncture I should say that I think we need some neater way to check such error conditions (the TypeError: Cannot read property 'hello' of undefined errors)

for example, Livescript uses ? for that checking:

if a?.x is 'something'
    do-something!

is compiled to

if ((typeof a != 'undefined' && a !== null ? a.x : void 8) === 'something') {
  doSomething();
}
Chris Reeves
@evs-chris
Mar 29 2018 14:48
@ceremcem @amadanmath that would be an ideal use for a reference expression because ractive will protect you from null bits of keypath still
if that won't work, then at least moving the .foo into the keypath will e.g. @context.get(key + 'data.foo')
which is effectively the same as that reference expression except that it will still search up the context hierarchy for the first key whereas the ./ roots the reference expression to the immediate context
as long as you give it full keypaths to work with, ractive will try pretty hard to protect you from null references
Chris Reeves
@evs-chris
Mar 29 2018 14:55
if a safe reference operator makes it to stage 4 (maybe 3... has it already?), we will be pulling it in quick fast and in a hurry
amadanmath
@amadanmath
Mar 29 2018 15:08
@ceremcem Thanks, though my code is somewhat different. I did manage to find a workaround for it. But in my code, I can't really predict when the error happens, since an almost same code elsewhere it doesn't throw the error. This was just the shortest example where I could replicate the error I was getting. At least I'd understand the TypeError: Cannot read property 'hello' of undefined; but with TypeError: model.getKeypath is not a function I'm stuck, as it's not part of my code.
Chris Reeves
@evs-chris
Mar 29 2018 15:16
interesting
that is a bug, as you should be able to safely reference a context model in an expression
@amadanmath I'll get a patch in for it in a bit
Chris Reeves
@evs-chris
Mar 29 2018 15:34
should be good to go on edge once travis does its thing, though the playground may not work immediately due to sticky caches
I need to get round to adding cache-busting support to the playground sooner rather than later
amadanmath
@amadanmath
Mar 29 2018 16:05
Cheers!
Cerem Cem ASLAN
@ceremcem
Mar 29 2018 17:10
wow! @evs-chris , the fastes bug shooter of the west :D