These are chat archives for ractivejs/ractive

30th
Jan 2018
Joseph
@fskreuz
Jan 30 2018 14:57

Is it reasonable to test rollup/webpack loaders as just functions? Is there any need to bring in/set up an actual Rollup/Webpack setup and compare generated code?

Rollup transforms look like:

export default function(options){
  return {
    name: '...',
    transform: (source, id) => ({ code, map })
  }
}

Webpack loaders look like:

module.exports = function(source){
  ...
  this.callback(err, code, map)
}

SystemJS is more or less on the same boat:

exports.translate = load => {
  ...
  return code
}
Chris Reeves
@evs-chris
Jan 30 2018 15:34
I'd say it's probably safe enough to just test the function. Comparing generated output, while safer, is one of the leading causes of both tooth decay and carpel tunnel.
Joseph
@fskreuz
Jan 30 2018 16:51
:D
Paul Maly
@PaulMaly_twitter
Jan 30 2018 18:22
@evs-chris need your advise
Paul Maly
@PaulMaly_twitter
Jan 30 2018 18:27
{{#await cart}}
Loading cart....
{{then data}}
<ul>
    {{#each data.products as product}}
     <li>
           {{ product.title }} - {{ product.pice }} <button on-click="splice('data.products', @index, 1)">x</button>
     </li>
     {{/each}}
</ul>
{{/await}}
Why it's not working?
Seems data.products is not appropriate binding
Chris Reeves
@evs-chris
Jan 30 2018 18:31
that looks like it should work
may be a bug
Paul Maly
@PaulMaly_twitter
Jan 30 2018 18:54
Looks like a bug: playground
Chris Reeves
@evs-chris
Jan 30 2018 18:55
ah, hold on... the button part was off of my screen
yep, @context (also, @.set for less ambiguity)
Paul Maly
@PaulMaly_twitter
Jan 30 2018 18:57
hm, very interesting
could you please little bit explain that moment? actually, I never needed to use @context before
Chris Reeves
@evs-chris
Jan 30 2018 19:05
@context is the current context in the template. Since ractive.set('foo.bar', ...) is always going to set 'foo.bar' relative to the root because the root is the context for the instance - it has no knowledge of wherever you're making the call from the template
The context handle lets you stay relative with your keypaths wherever you are in the template - it's the same mechanism that events use to allow relative data access.
Paul Maly
@PaulMaly_twitter
Jan 30 2018 19:15
ok, seems I got it. So, it's proper way to handle this case ?
Or I can do the same without @context too, somehow
Chris Reeves
@evs-chris
Jan 30 2018 19:18
nope, when you get into an {{#await}}{{then}} you're referencing data that only exists in the template, so there's no way around the @context
Paul Maly
@PaulMaly_twitter
Jan 30 2018 19:18
ok, thanks!
Chris Reeves
@evs-chris
Jan 30 2018 19:18
it's also useful for doing stuff in loops without fragile @keypath gymnastics