These are chat archives for canjs/canjs

15th
Mar 2016
Viktor Busko
@Lighttree
Mar 15 2016 12:27
@cherifGsoul besides I've fixed issue, that I mention yesterday... it was typo in bindings (facepalm) I didn't saw that in one case we use {{..}} and in another {(..)}, I've expected to see double curly braces everywhere, so my eye didn't notice {()} :)
Mohamed Cherif Bouchelaghem
@cherifGsoul
Mar 15 2016 12:50
@Lighttree ok, good :)
Dovid Bleier
@dbleier
Mar 15 2016 20:46
I am recursively calling setTimeout and when I do, stache never renders. I think the reason is because can-wait overrides setTimeout with it's own version. And then waits for it to resolve before rendering, but since it is recursive, it never finishes. How to get around this?
  loadSlide(slides, index) {
    var self = this, cs = slides[index], 
    next = (index + 1) % slides.length;
    this.attr('currentSlide', cs);
    setTimeout(function() {
      self.loadSlide.call(self, slides, next);
    }, 
      cs.props.duration * 1000
    );
  },
Thomas Sieverding
@Bajix
Mar 15 2016 20:50
Why would that be part of your zone?
Dovid Bleier
@dbleier
Mar 15 2016 20:51
why would what be part of my zone?
Thomas Sieverding
@Bajix
Mar 15 2016 20:51
can-wait
Also, can-wait seems kind of like a hacky approach to control flow
Dovid Bleier
@dbleier
Mar 15 2016 20:52
I don't know. I just stepped into setTimeout and I see it's calling can-wait. I think I am still on donejs 0.6.0
Thomas Sieverding
@Bajix
Mar 15 2016 20:52
I see
Dovid Bleier
@dbleier
Mar 15 2016 20:52
I didn't choose this, seems donejs did
Thomas Sieverding
@Bajix
Mar 15 2016 20:53
I don’t know enough here to give you a good answer
Dovid Bleier
@dbleier
Mar 15 2016 20:53
I would be happy to use standard js setTimeout, unless someone has a better idea
thanks for trying
Kevin Phillips
@phillipskevin
Mar 15 2016 20:55
can you try wrapping that code so it won’t run on the server?
if (System.isPlatform(‘window’)) { … }
Dovid Bleier
@dbleier
Mar 15 2016 20:56
what do you mean? I am not using can-ssr, I am running in the browser on a simple python http server with development.html
Kevin Phillips
@phillipskevin
Mar 15 2016 20:58
oh
I didn’t think setTimeout would be overridden on the client
Dovid Bleier
@dbleier
Mar 15 2016 20:59
but it seems to be.
when I stepped into setTimeout I got
        return new Override(g, "setTimeout", function(setTimeout){
            return function(fn, timeout){
                var callback = waitWithinRequest(function(){
                    delete request.ids[id];
                    return fn.apply(this, arguments);
                });
                var timeoutId = setTimeout.call(this, callback, timeout);
                var id = timeoutId;
                if(isNode) {
                    id = timeoutId.__timeoutId = globalTimeoutId++;
                }
                request.ids[id] = timeoutId;
                return timeoutId;
            }
        });
Kevin Phillips
@phillipskevin
Mar 15 2016 21:01
maybe @matthewp can weigh in
Matthew Phillips
@matthewp
Mar 15 2016 22:19
Yeah, if you are recursively calling setTimeout you will want to ignore that
you can do var ignore = require('can-wait/ignore')
which allows you to wrap some code you want to run outside of the zone
var fn = ignore(function() { setTimeout(function{ .... } } )
fn(); // You'll get the real setTimeout
Thomas Sieverding
@Bajix
Mar 15 2016 22:20
@matthewp What is can-wait being used for? Compatibility layer for SSR?
Matthew Phillips
@matthewp
Mar 15 2016 22:20
Yes, it is how we know when rendering is complete on the server
Thomas Sieverding
@Bajix
Mar 15 2016 22:20
I was under the impression that only deferreds mattered
Matthew Phillips
@matthewp
Mar 15 2016 22:21
In 0.5.0 we forced you to do this.attr("@root").waitFor(deferred)
but in 0.6.0 we added can-wait
which prevents the need for that
Thomas Sieverding
@Bajix
Mar 15 2016 22:22
So you’re hijacking timers & promises instead of doing a root level Promise.all
Matthew Phillips
@matthewp
Mar 15 2016 22:23
we're hijacking async code so that we are aware of when it happens
so you don't have to manually tell us all of your deferreds
Thomas Sieverding
@Bajix
Mar 15 2016 22:24
That has unintended consequences though
Matthew Phillips
@matthewp
Mar 15 2016 22:25
what are those consequences?
Thomas Sieverding
@Bajix
Mar 15 2016 22:25
For example, when I worked at Pluto, we would use promises both in our A/B testing flow, and for wrapping modal life cycles to do complex chaining
I can think of dozens of cases in which we’ve used promises & timers in which we wouldn’t want those to prevent SSR
Matthew Phillips
@matthewp
Mar 15 2016 22:27
You were using promises that didn't result in the UI changing?
That is the purpose, to know when rendering is complete
Thomas Sieverding
@Bajix
Mar 15 2016 22:29
I suppose we could have disabled those modals if we were rendering server side
It would result in UI changing, however there would be a sizable delay
Matthew Phillips
@matthewp
Mar 15 2016 22:30
Yes, you can selectively render stuff of course
use helpers to only render certain parts in the client
Thomas Sieverding
@Bajix
Mar 15 2016 22:30
can-wait always gets loaded?
Matthew Phillips
@matthewp
Mar 15 2016 22:32
it's used by done-autorender
so if you're not using that, no it does not
Thomas Sieverding
@Bajix
Mar 15 2016 22:33
I see
Matthew Phillips
@matthewp
Mar 15 2016 22:34
by the way, angular 2 has essentially the same sort of thing.
Thomas Sieverding
@Bajix
Mar 15 2016 22:34
Feels dirty ;x
Matthew Phillips
@matthewp
Mar 15 2016 22:34
for their ssr solution
Thomas Sieverding
@Bajix
Mar 15 2016 22:34
But I suppose that’s acceptable for SSR
Matthew Phillips
@matthewp
Mar 15 2016 22:34
It only applies to the initial render
once the page is loaded our overrides are gone
I like it because it leads to more elegant user code
you can do new XMLHttpRequest() and we'll know to wait for that
or return User.getList() and we know about it
Thomas Sieverding
@Bajix
Mar 15 2016 22:37
Will done-autorender work w/ precompiled stache templates
Matthew Phillips
@matthewp
Mar 15 2016 22:38
what is a precompiled stache template?
I think the answer is yes because i don't know what that is :)
done-autorender is like the stache/system plugin but applies to the main template only
so if you know a little about stache/system it's similar in what it does
but it also inserts the rendered fragment into the page for you
Thomas Sieverding
@Bajix
Mar 15 2016 22:40
define([
  "module",
  "can/view/stache/stache",
  "can/view/stache/mustache_core"
],function(module, stache, mustacheCore){
    var renderer = stache([{"tokenType":"start","args":["p",false]},{"tokenType":"end","args":["p",false]},{"tokenType":"chars","args":["I'm a little tea pot"]},{"tokenType":"close","args":["p"]},{"tokenType":"done","args":[]}]);
    can.view.preload("test_stache", renderer);
    return function(scope, options, nodeList){
        var moduleOptions = { module: module };
        if(!(options instanceof mustacheCore.Options)) {
            options = new mustacheCore.Options(options || {});
        }
        return renderer(scope, options.add(moduleOptions), nodeList);
    };
});
If I wanted to use done-autorender w/ something like that
My builds do *.stache -> .stache.js, and utilize configuration so that I don’t need the !plugin syntax
If I were to be using done-autorender, I would be loading the pre-compiled stache JS file
Thomas Sieverding
@Bajix
Mar 15 2016 22:45
done-autorender seems problematic because it’s dependent on doing an ad-hoc stache translation
Not to mention the coupling w/ live-reload ;(