These are chat archives for canjs/canjs

28th
Nov 2016
swipie
@swipie
Nov 28 2016 09:31

I'm trying to display data that I get from a request. I'm using can 3.1.0.
The data I get from the request is correct but the promise is always being rejected.

The following is in my .js file:

profiles: {
    get : function(lastValue, resolve) {
        var promise = ProfileModel.getList({});
        promise.then(function(data) {
            resolve(data); // if I print the data, the data is correct
        });
        return promise;
    }
},

My model:

export const Profile = DefineMap.extend('Profile', {
    id: "number",
    name: "string"
});

Profile.List = DefineList.extend('ProfileList', {
    '*': Profile
});

export const profileConnection = baseMap({
    url: {
        getListData: "POST /Profiles/getProfiles"
    },
    Map: Profile,
    List: Profile.List,
    name: 'profile'
});

My stache file

{{#if profiles.isPending}}
    <p>Pending</p>
{{else}}
    {{#each profiles}}
        <p>{{id}}</p>
        <p>{{name}}</p>
    {{/each}}
{{/if}}

Response of the server : [{"id":1,"name":"Test 1"},{"id":2,"name":"Test 2"}]

swipie
@swipie
Nov 28 2016 12:13
We found the problem, Stealjs was added 2 times to the page.
Nico R.
@nriesco
Nov 28 2016 14:12
@swipie still you should probably check if the promise was resolved
{{#if yourPromise.isPending}}
  Loading...
{{/if}}
{{#if yourPromise.isRejected}}
  Error
{{/if}}
{{#if yourPromise.isResolved}}
  {{#each yourPromise.value}}
    your results
  {{/else}}
    no results
  {{/each}}
{{/if}}
Viktor Busko
@Lighttree
Nov 28 2016 15:11

Hi guys, I have a collection of users ~1000 items there. And I'm implementing filter for this collection by its fields and this logic will be a bit more complicated later. The problem is that even now this filter seems quite slow especially in IE11. I think this might be related to wrong using can.map or something like that. Maybe someone can have a look on this fiddle and help: https://jsfiddle.net/lighttree/L3rkts9p/3/

Just if someone interested, I fixed this by changing logic to just change display property . It seems that the problem was in too many DOM operations.
can.batch might help as well I think, but I didn't try and read about it just today :D

Viktor Busko
@Lighttree
Nov 28 2016 15:30
can.Component.extend({
        tag: 'participants-list',
        events: {
            "inserted": function(el, ev){
                console.log('WHYYYY?')
            }
        },
        template: can.view('#participantsList-template'),
        viewModel: participantsListViewModel,
    });
Maybe someone knows does 'inserted' event requires some additional (except can.jquery.js) js to be included ? I see that my component works fine, but this event doesn't work :( There is a code for this inserted hook but still
Viktor Busko
@Lighttree
Nov 28 2016 16:48
Ok the issue above is because I used native DOM API for adding elements instead of jQuery.
Gregg Roemhildt
@roemhildtg
Nov 28 2016 16:55
@Lighttree I've run into that before. As a side note, the new can3.0 works without jquery, so you can use the nativ dom api
Viktor Busko
@Lighttree
Nov 28 2016 16:56
yeah but I can't migrate to newer versions of can right now :(