These are chat archives for canjs/canjs

17th
Jul 2017
AntonProkofyev
@AntonProkofyev
Jul 17 2017 10:59

hi guys,
i'm tring to pass asynchronous parameter from parrent component to child component with one-way data binding to child but got

Uncaught TypeError: Cannot define property Symbol(can.observeData), object is not extensible
    at Function.defineProperty (<anonymous>)
    at initPromise (can-reflect-promise.js:43)
    at AppViewModel.<anonymous> (can-reflect-promise.js:103)
    at Object.getKeyValue (get-set.js:75)
    at Object.read (can-stache-key.js:144)
    at Object.read (can-stache-key.js:60)

my parrent viewModel is

let ViewModel = DefineMap.extend({
    user: {
        get: function (last, resolve) {
            return personConnection.get({}).then(resolve);
        }
    }
}

without 'return' in get function i've got an error all the time, but with it, it works fine at least in parent component

parrent component template is

{{user.firstName}}
<childConmonent  {user}="user"></childComponent>

what's wrong with this?

Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:15
@AntonProkofyev what is personConnection??
AntonProkofyev
@AntonProkofyev
Jul 17 2017 12:17
const personConnection = connect(
    [authBehavior, constructor],
    {
        url: { getData: 'GET /persons' }
    });
where the authBehavior is custom behavior which was build on top of standart url one
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:19
@AntonProkofyev I see you use presonConnection instead of the map of that connection!!
@AntonProkofyev You should use Person.get(aUserId)
AntonProkofyev
@AntonProkofyev
Jul 17 2017 12:21
mmm so i need to add map behavior ?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:21
@AntonProkofyev can you share your Person map and connection definition?
I think so
otherwise you have to implement your own behavior if you like to use can-connect
AntonProkofyev
@AntonProkofyev
Jul 17 2017 12:23
i don't like ) but i need to use custom behavior to make two requests (one auth for token and then real one)
that's what authBehavior do
with models it was easier
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:25
what you mean by "with model"?
Auth is not done one time? and maybe you send it in the headers for each request?
AntonProkofyev
@AntonProkofyev
Jul 17 2017 12:27
yep
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:28
can you post your use case in the forums? http://forums.donejs.com/
AntonProkofyev
@AntonProkofyev
Jul 17 2017 12:29
ok i will try thx
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:30
you are welcome, just try to use the connection with a map and without Auth the get method needs an argument (eg: Id)
AntonProkofyev
@AntonProkofyev
Jul 17 2017 12:31
ok and if i need to get something without argument ?
anyway will try to use map behavior
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 12:32
what is the use case? getis to fetch one resource instance from web service for example, if you have another use case maybe using ajax in the component viewModel is simpler and do the job
AntonProkofyev
@AntonProkofyev
Jul 17 2017 13:20

mmm ok i just have a try to implement it with ajax but still got an error

const AppViewModel = DefineMap.extend({  
    user: {
        get: function (last, resolve) {
            $.ajax({
                url: '/authServlet',
                type: 'GET'
            }).then(function(response){
                return $.ajax({
                    type: 'GET',
                    url: '/person',
                    contentType: 'application/json',
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader('token', response.access_token);
                        xhr.setRequestHeader('lang', response.lang);
                    }
                })
            }).then(resolve);
        }
    }
});

/person returns {firstname:'foo', lastname'bar'}
the template is the same

{{user.firstname}}
<childConmonent  {user}="user"></childComponent>

and in child i just have

{{user.firstname}}

now i got

WARN: can-stache/src/expression.js: Unable to find key or helper "test.firstname".

jQuery.Deferred exception: Cannot define property _instanceDefinitions, object is not extensible TypeError: Cannot define property _instanceDefinitions, object is not extensible
    at Function.defineProperty (<anonymous>)
    at Object.defineExpando (https://localhost:3000/main.bundle.js?41ede84ce6df13df4e78:19848:11)
    at DefineMap.setKeyValue (https://localhost:3000/main.bundle.js?41ede84ce6df13df4e78:11105:30)
    at Object.setKeyValue (https://localhost:3000/main.bundle.js?41ede84ce6df13df4e78:15032:23)
    at Observation.observation.(anonymous function) (https://localhost:3000/main.bundle.js?41ede84ce6df13df4e78:45397:18) ....

sorry for a lot of text (

Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 13:22
"test.firstname" or "user.firstname"?
AntonProkofyev
@AntonProkofyev
Jul 17 2017 13:23
user.firstname
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 13:23
the quick fix:
const AppViewModel = DefineMap.extend({
 seal: false
},{... })
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 13:28
English is not my 1st language :)
AntonProkofyev
@AntonProkofyev
Jul 17 2017 13:29
=)
yes it helps
thank you a lot
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 13:30
no problem
AntonProkofyev
@AntonProkofyev
Jul 17 2017 13:30
is the DefineMap sealed by default?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 13:32
yes
I think is sealed when you extend it, if you instantiate (new DefineMap({foo:bar}) it is not sealed
AntonProkofyev
@AntonProkofyev
Jul 17 2017 13:37
thx you again, you helped me a lot
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 17 2017 13:39
any time :)