These are chat archives for canjs/canjs

10th
Jul 2018
srikkanthsiki
@srikkanthsiki
Jul 10 2018 00:40
any sample code using react-reuter4
router*
srikkanthsiki
@srikkanthsiki
Jul 10 2018 04:03
does can.js support react-router ?
Viktor Busko
@Lighttree
Jul 10 2018 07:25

Hi,
From time to time I have following code in my components:

import Component from 'can-component';
import DefineMap from 'can-define/map/map';
import Entity from '~/models/entity.model';
import './entity-card.scss';
import view from './entity-card.stache';

export const ViewModel = DefineMap.extend({
    lang: {
        value() {
            return sessionStorage.getItem('lang');
        }
    },
    loggedInUser: {
        type: 'number',
        value() {
            return sessionStorage.getItem('personId');
        }
    }
});

export default Component.extend({
    tag: 'entity-card',
    ViewModel,
    view
});

These two properties actually global for my app, because it is info about logged In User and user language. Is there good approach that allows you store this info and easily access from Components or other parts of code ? Maybe some... global template scope or something. Another idea is to import/export appVM and store it there. I don't really like this sessionStorage solution since its quite explicit and it might be that something change it.

Julian
@pYr0x
Jul 10 2018 07:29
you can take a look in bitball
and its approach
have the same in my application..
qantourisc
@qantourisc
Jul 10 2018 07:33
@Lighttree I make a by-reference assingment to my global object. Then inside the view I do sessionStorage.lang.
still means you have to drag it in, but less to type
If you wish dry: you could extend from a viewmodel (map/definemap) that already has this predefined
Julian
@pYr0x
Jul 10 2018 08:14
you can with `can-value´
qantourisc
@qantourisc
Jul 10 2018 14:21
What is the "correct" way to call the init of the object I extended from ? atm using extended_from.prototype.init.bind(this)( arguments )
Kevin Phillips
@phillipskevin
Jul 10 2018 14:33
but extended_from.prototype.init.apply(this, arguments); is fine too
qantourisc
@qantourisc
Jul 10 2018 14:34
ty
Kevin Phillips
@phillipskevin
Jul 10 2018 14:35
no problem
qantourisc
@qantourisc
Jul 10 2018 15:20

@cherifGsoul

@qantourisc It depends on your use case, usually = works fine for most of cases.

Unless the property is not defined yet ;)

Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 10 2018 15:32
@qantourisc yes