These are chat archives for canjs/canjs

13th
Apr 2016
dylanrtt
@dylanrtt
Apr 13 2016 03:57
@gsmeets If you are saying your original instances do not have ids set, that sounds like a model store issue because save() isn't expecting multiple models in the response. If you are using can.Model, usually you override parseModel for example, but that may not be sufficient for this case, so try makeCreate and makeUpdate.
dylanrtt
@dylanrtt
Apr 13 2016 04:08
Something like this:
can.Model.extend({
    makeCreate: function(oldCreate) {
        return function(params, success, error) {
            var self = this,
                def = oldCreate(params).then(function(data) {
                    if (can.isArray(data)) {
                        return self.models(data);
                    } else {
                        return self.model(data);
                    }
                });
            def.then(success, error);
            return def;
        }
    }
},{});
Guido Smeets
@gsmeets
Apr 13 2016 06:45
the question I guess is can I force a submodel to be 'created' when its parent is being saved
Guido Smeets
@gsmeets
Apr 13 2016 07:34
hmm, from the looks of it it actually does work, I seem to be having some random behavior popping up at random times that messes things up
Guido Smeets
@gsmeets
Apr 13 2016 09:18
for those interested, I found my problem. The saving of the object triggered some events on my viewmodel that should only be firing when the user manipulates the UI. So I've worked around it by calling this.off() prior to the save, and this.on() after the save is done. Not ideal, but it works
Kevin Phillips
@phillipskevin
Apr 13 2016 13:49
@gsmeets would you mind posting your example with some code at http://forums.donejs.com/?
easier for people to find larger examples there and maybe someone can help find a more ideal solution
Guido Smeets
@gsmeets
Apr 13 2016 13:57
It's extremely specific tbh, this design is imposed due to some technical constraints like an external component I use
Normally I would've solved it differently
Kevin Phillips
@phillipskevin
Apr 13 2016 14:02
ok, maybe not worth posting then
Paul Tichonczuk
@tracer99
Apr 13 2016 15:58
Trying to upgrade a project from can 2.2 to 2.3. I'm running into an exception in compute/read.js:248 where parent is undefined. Changing the condition to parent && parent[key] && parent[key].isComputed prevents the exception from happening and doesn't seem to have any adverse effects on the execution. However, I'm having a really hard time figuring out why this exception happens at all. In 2.2, the same code never touched read.js
Any advice?
dylanrtt
@dylanrtt
Apr 13 2016 16:14
@tracer99 That is likely related to the new bindings. The change made was that can-value="key" will set the scope's key to the value of the element during initialization if key is undefined. This ensures consistency between the scope and element. The issue is if you have a parent like can-value="foo.bar" where foo is resolved asynchronously, the write fails because foo is undefined initially. Here is a breaking example that works in 2.2 http://jsbin.com/sibotojebo/edit?html,js,console,output
I previously reported this as issue #2020 (new bindings should behave this way, but old bindings should behave the old way) that was supposedly fixed, but I later found out it was not and didn't get around to re-reporting it because I had fixed all the cases where it was a problem.
This behavior can be good because it helps find bugs. To prevent the issue, you can use the template to delay the render of an element until the scope values you need are present, or add default values to your scope.
Paul Tichonczuk
@tracer99
Apr 13 2016 17:41
@dylanrtt We're not using Must/Stach or components. (our app pre-dates these things). However, I'm going to go over the EJS files to see if your comment still applies to those bindings though.
dylanrtt
@dylanrtt
Apr 13 2016 17:48
@tracer99 The bindings code is in view/bindings/bindings.js. You can throw some breakpoints in to see if it's being used, but I suspect not. If you pause on your error, the value of key may be helpful to track down where in your code the issue arises.
Paul Tichonczuk
@tracer99
Apr 13 2016 18:06
@dylanrtt Now it' sclear and makes sense. Thanks for the tip.
Christopher Oliphant
@RALifeCoach
Apr 13 2016 18:37
I am back talking about performance. I ran the same 156 rows in IE on windows 10. The load time was 27 seconds.
Thats just not going to fly with the client.
Julian
@pYr0x
Apr 13 2016 20:52
?