These are chat archives for canjs/canjs

7th
May 2018
Chasen Le Hara
@chasenlehara
May 07 2018 15:45
@pYr0x .set({prop: 'value'}) is deprecated, not .set('prop', 'value')
That deprecation warning will be a little better with the next release: canjs/can-define#328
@dbleier Hm, your stache template not updating when new data comes in doesn’t sound right… any chance you could share more of the code? What does the can-connect call look like, how are the props defined, & what the template looks like?
Julian
@pYr0x
May 07 2018 16:12
@chasenlehara ... ahh ;) ok !
Dovid Bleier
@dbleier
May 07 2018 19:00
@chasenlehara here is the code you requested
the model
import superMap from 'can-connect/can/super-map/';
import DefineMap from 'can-define/map/';
import DefineList from 'can-define/list/';
import tag from 'can-connect/can/tag/';
import 'can/map/define/';
import config from 'menuboard-manager/config/config/';
import set from 'can-set';

//import services from 'menuboard-manager/config/services/';

let algebra = new set.Algebra();
algebra.clauses.where = (a, b) => { return a.user === b.user; };

export const Sign = DefineMap.extend({
        define: {}
    }),

    SignList = DefineList.extend({
        "#": Sign
    }, {

    });
Sign.connection = superMap({
    url: config.attr('env').domain + 'get/1/',
    idProp: 'id',
    Map: Sign,
    List: SignList,
    name: 'sign',
    algebra: algebra
        //connectionAvailable: services.getService('network').checkNetworkStatus.bind(services.getService('network'))
});
Sign.connection.cacheConnection.getListDataInternal = Sign.connection.cacheConnection.getListData;
Sign.connection.cacheConnection.getListData = function(set) {
    return this.getListDataInternal({ mac: set.mac, user: set.user });
};
Sign.connection.cacheConnection.updateListDataInternal = Sign.connection.cacheConnection.updateListData;
Sign.connection.cacheConnection.updateListData = function(data, set) {
    var items = data.data,
        sets = this.getSetData(),
        setOverride = { mac: set.mac, user: set.user },
        setKey = JSON.stringify(setOverride),
        setDatum = sets[setKey];

    if (setDatum) {
        this.updateSet(setDatum, items);
    } else {
        this.addSet(setOverride, data);
    }

    return Promise.resolve();
};

Sign.connection.updatedList = (old, newdata) => {
    setTimeout(() => {
        Sign.loadSign(new DefineMap(newdata.data[0]));
    }, 1000);
};

tag('sign-model', Sign.connection);

export default Sign;
stache
{{#eq status 'loaded'}}
{{#with currentPresentation}}
    <style type="text/css" media="screen">
        {{#fonts}}
            @font-face {
                font-family: {{fontName(id)}}; 
                src: url({{luri}});
            }    
        {{/fonts}}
    {{#if css}}{{css}}{/if}}
    </style>
    <div id="fields">
        {{#each ./fields}}
            <div id:from="id" class:from="classes" style:from="parseCSS('field', cssrule)">{{value}}</div>
        {{/each}}
    </div>
    <div id="slideshows"></div>
    <can-import  from="./html-widget/html-widget" />
    <html-widget html:from="html" ></html-widget>
{{/with}}
{{else}}
    <span style="font-size:48pt; color: yellow;">{{status}}</span>
{{/eq}}
the call to the promise to get the sign and process it
    oninserted() {
        this.trace('in sign.inserted');
        var self = this;

        self.attr('inserted', true);
        self.attr('signPromise').then(function(signs) {
                self.finer('signs return from signPromise', signs);
                if (!signs.length) {
                    self.displayNoData();
                    return;
                }
                Promise.resolve(signs).then((signs) => {
                    self.finer('scrubbed sign', signs[0]);
                    self.loadSign(signs[0]);
                });
            })
            .catch((reason) => {
                console.log('Sign Promise failed', reason);
                self.error('Failed to Retrieve Sign from Server: ' +
                    reason.responseText, reason);
                self.status('Failed to Retrieve Sign from Server: ' + reason.responseText);
                self.displayNoData();
            });
    },
the promise prop
        signPromise: {
            get() {
                this.trace('in sign.signPromise Getter');
                this.status('Retrieving Sign Content Data...');
                Sign.loadSign = this.loadSign.bind(this);
                let params = this.getSignParams();
                if (params.user == null) {
                    return this.getUser(params).then(user => {
                        return Sign.getList(user);
                    });
                } else {
                    console.log('getting sign', params);
                    return Sign.getList(params);
                }
            }
        },
        sign: {
            get(last, set) {
                this.trace('in Sign Getter');
                var self = this;

                return last || this.attr('signPromise').then((signs) => {
                        var sign = signs[0];
                        !sign && self.error('No Signs Retrieved from Server');
                        set && set(sign);
                    })
                    .catch((err) => {
                        self.error('Sign Failed to Load: ' + err.message, err);
                    });
            }
        },
Chasen Le Hara
@chasenlehara
May 07 2018 19:23
Thanks @dbleier, so is the issue that the Sign.getList is returning cached data and then you’re expecting sign to be updated once the network request finishes?
Dovid Bleier
@dbleier
May 07 2018 20:14
right
Chasen Le Hara
@chasenlehara
May 07 2018 20:40
Ok, and the last little bit that’s not clear to me is how loadSign works and what the template renders; is the context of the stache template sign, or something made by loadSign?
One thing that’s a little weird to me is that sign returns either a sign or a Promise, depending on whether it’s been set. I don’t think that’d cause any problems, but I’m not 100% sure.
Julian
@pYr0x
May 07 2018 20:43
how gets a capital letter encoded in stache?
Chasen Le Hara
@chasenlehara
May 07 2018 20:43
I would change that logic to return last or undefined if it needs to fetch the sign:
                if (last) {
                    return last;
                }

                this.attr('signPromise').then((signs) => {
                    var sign = signs[0];
                    !sign && self.error('No Signs Retrieved from Server');
                    set && set(sign);
                })
                .catch((err) => {
                    self.error('Sign Failed to Load: ' + err.message, err);
                });
Julian
@pYr0x
May 07 2018 20:43
:U:
?
cant find it in the docs
Chasen Le Hara
@chasenlehara
May 07 2018 20:44
I think we intentionally don’t document the encoding, you can look at how it’s implemented though: https://github.com/canjs/can-attribute-encoder/blob/44a00dc0732e5675688af6425809f2223d8cb73c/can-attribute-encoder.js
I would use can-attribute-encoder’s encode/decode methods if you need to deal with the encoding.
Julian
@pYr0x
May 07 2018 20:45
<x-pie-chart headline:raw="Nach Protokollart" apiEndpoint:raw="logistics/by-protocol-types"></x-pie-chart>
i want something like this
Chasen Le Hara
@chasenlehara
May 07 2018 20:46
I think that should just work.
I haven’t used raw but I’m pretty sure that’s how it should work.
Same as apiEndpoint:from="'logistics/by-protocol-types'"
Julian
@pYr0x
May 07 2018 20:47
i am not on a stache file.. if this was in a stache file, yes i would work... but i used this component in a normal html file
the component is automouted
i tried <x-pie-chart headline:raw="Nach Protokollart" vm:api:u:endpoint:raw="logistics/by-protocol-types"></x-pie-chart>
but this is not working too
Chasen Le Hara
@chasenlehara
May 07 2018 21:00
Does api-endpoint:raw work?
Julian
@pYr0x
May 07 2018 21:05
no
Chasen Le Hara
@chasenlehara
May 07 2018 21:06
Ok, maybe this is a bug?
Julian
@pYr0x
May 07 2018 21:12
yeah... maybe
:)
i can check this if i finished the job i am working on
maybe on friday
Chasen Le Hara
@chasenlehara
May 07 2018 21:24
Cool, I filed an issue about it: canjs/can-attribute-encoder#21
Marc Godard
@MarcGodard
May 07 2018 23:16
@justinbmeyer Just saw this "can you create an issue in can-route? ... __url isn't documented, we will want to create something a bit more permanent" Sorry was moving and away for the last couple weeks. lol it was april 13th you asked that. Is this still needed?