These are chat archives for ractivejs/ractive

22nd
Oct 2017
lazylester
@lazylester
Oct 22 2017 01:44 UTC
I have a question regarding Ractive.defaults.data...
when components are written as ES6 modules
do defaults need to be "imported" in some manner?
or should they "just work"
I'm not seeing defaults.data in my components
Chris Reeves
@evs-chris
Oct 22 2017 02:13 UTC
The defaulted data keys should be present in the component data, as defaults.data is used as a prototype for instance data. If you change a default after instantiation, you will need to tell the relevant instances with update, though.
lazylester
@lazylester
Oct 22 2017 02:36 UTC
hmmm, I'm not seeing it. What's the best way to do a repro case, since the scenario involves multiple files?
Joseph
@fskreuz
Oct 22 2017 03:09 UTC
A demo repo with a sample use case, and the exact build procedures you are using would suffice.
Chris Reeves
@evs-chris
Oct 22 2017 03:10 UTC
out of curiosity, if you just go minimal with plain components inline, does it work as intended?
lazylester
@lazylester
Oct 22 2017 03:11 UTC
yes, Chris, it works in the simple case
Joseph
@fskreuz
Oct 22 2017 03:12 UTC
Using Ractive.defaults.data is like adding a polyfill. It's use case is to add default data before your app starts. If I were to decide where it's introduced, it would be with a side-effect-y import (i.e. import './something') in your entry point file, just before you instantiate the app.
Your build-step might also be mangling the order when that module appears in the bundle.
Chris Reeves
@evs-chris
Oct 22 2017 03:14 UTC
that's what I was thinking... maybe a circular dep that's breaking expectations
lazylester
@lazylester
Oct 22 2017 03:18 UTC
I'll work on a repro... sometimes (often) that process reveals the problem. At least I know my expectation is correct. Thanks for the tips. Stay tuned.
lazylester
@lazylester
Oct 22 2017 16:49 UTC
OK, made a very simple repro for this issue, and still seeing the problem. If you have a moment to look at https://github.com/lazylester/module_debug I'd appreciate any insight you can offer.
Chris Reeves
@evs-chris
Oct 22 2017 16:53 UTC
first glance it seems that the issue probably module hoisting
module imports are always all eval-ed before any of the current module code, so the defaults assignment gets bumped down to after the item import
not sure yet why that would mean that foo isn't available in the component...
lazylester
@lazylester
Oct 22 2017 17:39 UTC
Thanks for looking at it, Chris. I did try playing with the loading order, with no success.
Chris Reeves
@evs-chris
Oct 22 2017 18:45 UTC
When I get to a real machine, I'll clone it and see if I can figure out what's up
Chris Reeves
@evs-chris
Oct 22 2017 21:29 UTC
I'm not sure why I didn't catch this before, but you're actually replacing the default data, so the component can't inherit from it
if you Ractive.defaults.data.foo = 'qux' instead, it's closer
I think there's a bit of a bug here too, as you need to have a data dictionary for the component in order for it to be inherited, which I don't think should be the case
in the component: data: function() { return {}; } will do it
lazylester
@lazylester
Oct 22 2017 21:35 UTC
Great, Chris, thanks so much. That'll get me moving again.