These are chat archives for canjs/canjs

11th
Jan 2016
Gerard Finnerty
@halcyonandon
Jan 11 2016 22:55
Hi, this was likely previously discussed, but it used to be that canJS executed the inserted event of all child components prior to rendering the parent's inserted event... the thing is, we depend on the parent knowing of its children in the inserted event... e.g. a parent component has children each with a field, we register those fields on parent inserted for certain things, but they are no longer there because of the order change
Justin Meyer
@justinbmeyer
Jan 11 2016 22:56
@cherifGsoul was having a discussion with me about getting default values to work in can-define.
The problem was that a test like:
var Typer = function(prop) {
            this.prop = prop;
        }

        define(Typer.prototype, {
            prop: { value: 'foo' }
        });

        QUnit.equal(new Typer().prop, "foo", "value is used as default value");
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 22:57
@justinbmeyer yes
Justin Meyer
@justinbmeyer
Jan 11 2016 22:57
even if prop is not passed, Typer is still going to assign undefined to prop
so I suggested some alternate code
var Typer = function(props) {
   Object.assign(this, props);
}

....

new Typer({}).prop
the problem with this is Object.assign doesn't exist in all browsers :-(
we could use ES6 modules in the project
which would polyfill Object.assign
but I want to keep using CJS in most CanJS related projects
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 22:58
I like CJS too :)
Justin Meyer
@justinbmeyer
Jan 11 2016 22:59
so I asked @matthewp if theres a way to enable babel with CJS
(he's done w/ work today)
so I don't know
for now ... can.simpleExtend() could be used in place of Object.assign
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:00
for the early versions I think is ok with can.simpleExtend
@justinbmeyer Babel could have plugin for CJS
Justin Meyer
@justinbmeyer
Jan 11 2016 23:03
we don't need a babel plugin for CJS
we just ned babel to run as a transform hook for CJS code
it would be nice to have a simple flag like:
system: {babel: true}
which would run babel on every JS file directly w/i that project
or possibly put:
"babel";
as a statement in the files you want transformed
actually ... I would prefer something more like
import "es6";
which would tell steal to bring with polyfills and transforms
some type of "here's the current language capabilities this file needs"
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:06
the import statement will be in the can-define.js source file?
Justin Meyer
@justinbmeyer
Jan 11 2016 23:08
yeah
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:09
if the current release version will be based on can.Map we can use can.simpleExtend()
Justin Meyer
@justinbmeyer
Jan 11 2016 23:10
yeah
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:11
ok nice
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:22
@justinbmeyer does the suggested solution should be in the test? coz it dosent work for me
Justin Meyer
@justinbmeyer
Jan 11 2016 23:26
@cherifGsoul I'm not totally sure what you mean
yes ... the test needs to be changed
from what you originally posted
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:27
var Typer = function(prop) {
            //this.prop = prop;
             if(prop !== undefined) { this.prop = prop; }
            //can.simpleExtend(this,prop);
        }
Justin Meyer
@justinbmeyer
Jan 11 2016 23:28
is that calling this.prop = prop;?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:29
no
the definition:
define(Typer.prototype, {
            prop: { value: 'foo' }
});
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jan 11 2016 23:43
@justinbmeyer the defaults are not generated yet in the can-define like in the Map.define plugin