These are chat archives for canjs/canjs

14th
Jul 2017
Frank Lemanschik
@frank-dspeed
Jul 14 2017 12:28
https://www.npmjs.com/package/landscaper should be moved to a public accessible place so that some one can work more easy with it :)
AntonProkofyev
@AntonProkofyev
Jul 14 2017 13:46

Hi guys, i have a question
i have simple connect like
let userConnection = connect( [url, constructor], { url: { getData: 'GET /user' } });
which returns someting like {name: 'Name'}

i have wm

let AppViewModel = DefineMap.extend( {    
    user: {
        get: function (lastSetValue, resolve) {
            userConnection .get().then(resolve);
        }
    }
});

let appVM = new AppViewModel({});

i'm using simple template like {{user.name}}. But when i get response i can see name but i can also see
Uncaught (in promise) TypeError: Cannot define property _instanceDefinitions, object is not extensible define-helpers.js:17.
Am i doing anything wrong with asynchronous getters? May be someone know why is this error appears?

Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:47
ithink its because user.name
is not a property
but my english is to bad to explain you that better and shorter simply wait for some one but it looks like your doing it wrong
AntonProkofyev
@AntonProkofyev
Jul 14 2017 13:49
mmm i got response {name: 'Name'} from the server and i see Name on the page
Kevin Phillips
@phillipskevin
Jul 14 2017 13:50
can you put a breakpoint in define-helpers and see what property is being set?
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:50
i can't tell you more i never used it like you do
with the lastSetValue and resolve
i return the value and i get the value
Kevin Phillips
@phillipskevin
Jul 14 2017 13:50
take a look at canjs/can-route#98
see if it is the same thing you are doing @AntonProkofyev
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:53
@phillipskevin couldn't he directly return the promis and don't use resolve?
i think he could simply return userConnection.get() ?
Kevin Phillips
@phillipskevin
Jul 14 2017 13:53
he could, but it would make the template more complicated
and not fix this problem
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:53
why would that affect the template
i always return pormis
and get directly the value
Kevin Phillips
@phillipskevin
Jul 14 2017 13:54
you have to do user.value.name in the template
AntonProkofyev
@AntonProkofyev
Jul 14 2017 13:55
mmm let me check
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:55
hmmm i always do this each stuff for user.value
Kevin Phillips
@phillipskevin
Jul 14 2017 13:55
@AntonProkofyev the way your code is, user.name is fine
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:55
and that works great
ah
Kevin Phillips
@phillipskevin
Jul 14 2017 13:55
you can do it that way, @frank-dspeed
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:55
then i have no value when i use his code style
interristing
Kevin Phillips
@phillipskevin
Jul 14 2017 13:55
using the async getter with resolve, you don't have to do it that way
user is the value if you use resolve
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:56
but then i can also do no waiting like if isResolved right?
because i only get the value
i understand the diffrence is getting a promis or a value i understand
Kevin Phillips
@phillipskevin
Jul 14 2017 13:57
right
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:58
do you know a code that would allow me to change the value every x secunds?
Kevin Phillips
@phillipskevin
Jul 14 2017 13:58
I usually do promises like this:
    userPromise: {
        get: function () {
            return userConnection.get();
        }
    },
    user: {
        get: function(last, resolve) {
            this.userPromise.then(resolve);
        }
    }
so you can do userPromise.isResolved and also user.name
in the template
Frank Lemanschik
@frank-dspeed
Jul 14 2017 13:59
ah nice now i understand
why this is in some examples
i saw that :)
AntonProkofyev
@AntonProkofyev
Jul 14 2017 14:00
yep that's what i saw in docs and i can see name when it's resolved...
i've add breakpoint but it gives nothing. just see that Object.defineProperty(map, "_instanceDefinitions", { make an error
and that map constructor is DefineMap
Frank Lemanschik
@frank-dspeed
Jul 14 2017 14:00
but do you know a way to reset a value with a interval?
Kevin Phillips
@phillipskevin
Jul 14 2017 14:00
@frank-dspeed use a setter
Frank Lemanschik
@frank-dspeed
Jul 14 2017 14:00
how you mean that?
i have really no idea about that because for me a setter gets only called on set
and then you mean i can do var x = interval() in the setter
Kevin Phillips
@phillipskevin
Jul 14 2017 14:01
foo: {
  value: 1,
  set(val) {
    setTimeout(() => { this.foo+=1 }, 1000);
    return val;
  }
}
Frank Lemanschik
@frank-dspeed
Jul 14 2017 14:01
and it gets executed?
and that gets automatic executed?
does the setter get executed with value ?
Kevin Phillips
@phillipskevin
Jul 14 2017 14:02
yeah
Frank Lemanschik
@frank-dspeed
Jul 14 2017 14:02
ok ok
looks pritty cool
Kevin Phillips
@phillipskevin
Jul 14 2017 14:03
@AntonProkofyev can you check what is propand value ?
and walk up the stack to the first place that is in your code
to see what is being called
AntonProkofyev
@AntonProkofyev
Jul 14 2017 14:31
can you —Ālarify plz what you mean by checking what is prop and value
i can see that this defineMap appears somwhere near reflection/get-set
setKeyValue
Kevin Phillips
@phillipskevin
Jul 14 2017 14:35
the parameters that function is being called with
AntonProkofyev
@AntonProkofyev
Jul 14 2017 14:40
i can see that this defineMap is definening in can-stache-bindings.js in
var viewModel = bindingData.getViewModel()
prop is name
Frank Lemanschik
@frank-dspeed
Jul 14 2017 14:42
as i sayed you need to define name in your model first
AntonProkofyev
@AntonProkofyev
Jul 14 2017 14:42
value is definemap
{name:Name}
@frank-dspeed what do you mean? can you clarify plz
Frank Lemanschik
@frank-dspeed
Jul 14 2017 14:45
your applying can-connect to a Model right?
a defineMap
AntonProkofyev
@AntonProkofyev
Jul 14 2017 14:48
i would like to add the response obj to the viewmodel of a component
viewmodel is defineMap
AntonProkofyev
@AntonProkofyev
Jul 14 2017 15:02
may be there is any different sollution?
Gregg Roemhildt
@roemhildtg
Jul 14 2017 18:30
@phillipskevin I think canjs/canjs#3427 is actually related to my can-connect behavior. I got into ios debugging and it looks like my parseInstanceData is not being called at all which is generating the issues with the data retrieved.
Kevin Phillips
@phillipskevin
Jul 14 2017 18:31
a custom behavior you mean?
Gregg Roemhildt
@roemhildtg
Jul 14 2017 18:32
Yes
I think it might have to do with the order of the custom/builtin behaviors
Justin Meyer
@justinbmeyer
Jul 14 2017 18:54
Contributor meeting: https://www.youtube.com/watch?v=dmwV1U3ExSQ Shows ReactViewModels, steams, and the incremental SSR stuff we have been working on
Gregg Roemhildt
@roemhildtg
Jul 14 2017 20:15
What's the best order to put can-connect behaviors in? currently I have this, but its still not working on ios...
    var behaviors = [
        canConstructor,
        canMap,
        canRef,
        RestlessData, //custom getlist, createdata, getdata, etc
        constructorStore,
        dataCallbacks,
        dataParse,
        RestlessParse, //custom parseListProp, parseInstanceData 
        realTime,
        callbacksOnce
    ];
Gregg Roemhildt
@roemhildtg
Jul 14 2017 20:20
parseInstanceData still is never called, on ios, unless I move it up the list. Is there a good way to know where to place it?
Justin Meyer
@justinbmeyer
Jul 14 2017 21:03
@roemhildtg only ios?