These are chat archives for canjs/canjs

24th
Jul 2017
Viktor Busko
@Lighttree
Jul 24 2017 09:55
Hi, when I write something like:
<h3 class="userCard-userName">{{currentPerson.firstname}} {{currentPerson.lastname}}</h3>
I have a warning in console:
WARN: can-stache/src/expression.js: Unable to find key or helper "currentPerson.imageUrl".
It doesn't break anything, but annoys a bit. Besides currentPerson is in viewModel, what exactly wrong with {{currentPerson}} notation, because I think I have the same warning in other places when show some info on the page.
Frank Lemanschik
@frank-dspeed
Jul 24 2017 09:57
post me how you defined currentPerson
unable to find key or helper means it cant find the .imageUrl key in that
Viktor Busko
@Lighttree
Jul 24 2017 09:57
const ViewModel = DefineMap.extend({
    currentPerson: {
        value: {}
    }
});
Frank Lemanschik
@frank-dspeed
Jul 24 2017 09:58
hmmm ok that could get complicated
value returns simply a object right?
Viktor Busko
@Lighttree
Jul 24 2017 09:58
yep
Frank Lemanschik
@frank-dspeed
Jul 24 2017 09:59
i know exactly that this will not work thats what the warning tells you but i am at present not deep into canDefine so i can't tell you the right syntax for that :)
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 24 2017 09:59
@Lighttree does ViewModel has imageUrl property
Frank Lemanschik
@frank-dspeed
Jul 24 2017 09:59
a tip from me where i know it works and maybe its the right way to create a extra defineMap for a Person
and return that
you should create a extra Person Model
and assign that to currentPerson
@Lighttree are you using donejs?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 24 2017 10:01
imageUrl is called somewhere
Viktor Busko
@Lighttree
Jul 24 2017 10:01
ok I think I understand where to look
Frank Lemanschik
@frank-dspeed
Jul 24 2017 10:01
@cherifGsoul <h3 class="userCard-userName">{{currentPerson.firstname}} {{currentPerson.lastname}}</h3>
I have a warning in console:
WARN: can-stache/src/expression.js: Unable to find key or helper "currentPerson.imageUrl".
It doesn't break anything, but annoys a bit. Besides currentPerson is in viewModel, what exactly wrong with {{currentPerson}} notation, because I think I have the same warning in other places when show some info on the
Viktor Busko
@Lighttree
Jul 24 2017 10:01
No, i'm using just canjs
Frank Lemanschik
@frank-dspeed
Jul 24 2017 10:02
he uses it as a sub value of current person
so the imageUrl is a property of current person
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 24 2017 10:03
if he does not trying to read it (imgUrl) in stache the wraning would not be displayed
Frank Lemanschik
@frank-dspeed
Jul 24 2017 10:03
but he reads it
ah
right
wait right cherif you got it !!!
:D
@Lighttree you need to use it in your stache ;)
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 24 2017 10:04
<h3 class="userCard-userName">{{currentPerson.firstname}} {{currentPerson.lastname}}</h3> where is imageUrl??
ctrl + f (cmd f) in your editor and look for imageUrl
Frank Lemanschik
@frank-dspeed
Jul 24 2017 10:08
@cherifGsoul do you think its a bad idea to raise a issue about that where we proposal to adjust that WARN ???
so it returns a url with possible situations where that happens?
or why it happens
?
Mohamed Cherif Bouchelaghem
@cherifGsoul
Jul 24 2017 10:10
a URL ?? you mean the filename?? yes file the issue why not
Frank Lemanschik
@frank-dspeed
Jul 24 2017 10:11
we could place a direct link in that error msg so the user gets more information about such stuff
Frank Lemanschik
@frank-dspeed
Jul 24 2017 10:24
the link could point to a new FAQ Page like in issue #3404
Viktor Busko
@Lighttree
Jul 24 2017 14:07

Still can't fix these warnings :)

I have just list:

<ul class="list">
    {{#entitiesList}}
        something
    {{/entitiesList}}
</ul>
export const ViewModel = DefineMap.extend({
    entitiesList: {
        Type: [Entity],
        get(lastSet, resolve) {
            Entity.getList({}).then(resolve);
        }
    }
});

and it warns me:
can-stache/src/expression.js: Unable to find key or helper "entitiesList".

There is a stack-trace actually so I see from what template it goes.

Kevin Phillips
@phillipskevin
Jul 24 2017 14:08
because entitiesList is async
it will be undefined at first
Viktor Busko
@Lighttree
Jul 24 2017 14:09
yeah I was thinking about this, but how to avoid this ? because I have tons of async data and my console full of this warnings :)
Frank Lemanschik
@frank-dspeed
Jul 24 2017 14:09
fix would be to remove the then resolve and directly use the promis in the template
Kevin Phillips
@phillipskevin
Jul 24 2017 14:09
{{#if entitiesList}}
  {{#each entitiesList}}
  {{/each}}
{{/if}}
Frank Lemanschik
@frank-dspeed
Jul 24 2017 14:09
on isResolved
return directly Enity.getList
Viktor Busko
@Lighttree
Jul 24 2017 14:14
yeah helped, thanks
Paul Tichonczuk
@tracer99
Jul 24 2017 19:29

We ran into a strange issue while writing a unit test on a Define Map based View Model.

vm.someparam.should.be.empty(); // throws an error even though it's an empty string
let someparam = vm.someparam;
someparam.should.be.empty(); // test passes

any suggestions?

Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:38
i don't fully understand the issue maybe give more information like what error do you get?
Paul Tichonczuk
@tracer99
Jul 24 2017 19:38
I don't know what more I can tell you. It's a very basic test
vm.someparam is an empty string
the first test fails. the second test passes even though I'm testing the same thing
Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:39
and what error does it throw
there needs to be a error msg with stack trace
Paul Tichonczuk
@tracer99
Jul 24 2017 19:39
it's doesn't throw an error
Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:39
normaly
Paul Tichonczuk
@tracer99
Jul 24 2017 19:39
it's a testing framework
Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:39
vm.someparam.should.be.empty(); // throws an error even though it's an empty string
but you say here it throws
Paul Tichonczuk
@tracer99
Jul 24 2017 19:39
sorry... I meant the test fails
Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:40
what framework are u using for the unit tests
what does be.empty() expect?
Paul Tichonczuk
@tracer99
Jul 24 2017 19:41
mocha/chai
Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:41
i need to reproduce the full error if i can't get the same results like you i cant help
so post me your vm code
Paul Tichonczuk
@tracer99
Jul 24 2017 19:41
with should assertian
errr... that's not practical
this is not a simple stand alone example
i'll try to reproduce it in a stand alone example
Frank Lemanschik
@frank-dspeed
Jul 24 2017 19:42
ok then at last i cant help you but feel free to post a issue on https://github.com/canjs/canjs/issues
i think it has something to do with how can-define-map works it transforms your values to computes but i am wondering why the let is then empty
kostya.aderiho
@kaderiho
Jul 24 2017 20:13
Hi everyone, could someone explane what can.set.Algebra is in canjs 3.9.0 and why we should use it? I have read doc about this, but still have some gaps in understanding. Thank you in advance.
Gregg Roemhildt
@roemhildtg
Jul 24 2017 20:21
anyone know what this error means?
image.png
Frank Lemanschik
@frank-dspeed
Jul 24 2017 20:22
it defines what value gets set where on your view model its a mapping of values for can-connect @kaderiho
Kevin Phillips
@phillipskevin
Jul 24 2017 20:23
@tracer99 it's probably because can-define is using a getter/setter behind the scenes
Frank Lemanschik
@frank-dspeed
Jul 24 2017 20:23
@roemhildtg i saw this error sometimes ago it looks like you need to upgrade/update some modules
Kevin Phillips
@phillipskevin
Jul 24 2017 20:24
@roemhildtg are you doing this? canjs/can-route#98
Gregg Roemhildt
@roemhildtg
Jul 24 2017 20:25
hmm, I am using can-route
But not exactly like that. I'll look into that
Kevin Phillips
@phillipskevin
Jul 24 2017 20:26
you should be able to put a breakpoint in that define-helpers file and trace the stack back up to what you're calling
Gregg Roemhildt
@roemhildtg
Jul 24 2017 20:29
I think I got it. I had a route map without seal:false
Kevin Phillips
@phillipskevin
Jul 24 2017 20:40
ok
you can post that in the issue
or a new issue
maybe that's something we should fix
Frank Lemanschik
@frank-dspeed
Jul 24 2017 20:42
at last this needs to get documented
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 20:52
hi all, I am using {{data name}} on an element and when it is clicked I am using $el.data("name") to retrieve the data. This was working previously but I am guessing this has been deprecated. can you point me to a different way of getting that functionality, if possible?
Kevin Phillips
@phillipskevin
Jul 24 2017 21:00
how are you calling the click handler?
Gregg Roemhildt
@roemhildtg
Jul 24 2017 21:02
Does can-route support using nested properties? Likes route('{obj.data}/{obj.id}')
Kevin Phillips
@phillipskevin
Jul 24 2017 21:04
@ranjanbuilds you can do something like <div name="the-name" ($click)="clickHandler(%element.getAttribute('name'))">Click Me</div>
not sure if that will work for you without some more information
Kevin Phillips
@phillipskevin
Jul 24 2017 21:11
@ranjanbuilds I submitted canjs/canjs#3446 if you want to add any additional information
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 21:19

thanks Kevin, heres a little more detail on how we used it:

Three different links to three different testimonials that opens a popup when clicked. Testimonial info saved in an array of objects. Using {{#each}} we created testimonial links and included {{data 'testimonial'}}. Used an event trigger ".videoPopup click: ($el, ev) => {}" where we found the testimonial object using $el.data("testimonial") and set the property popUpOpen to true if it was clicked.

I think using ($click) I can pass the popUpOpen property directly to clickHandler and set it to true
@phillipskevin ^
Kevin Phillips
@phillipskevin
Jul 24 2017 21:21
ok, thanks for explaining
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 21:31
this isn't working but it is what I am going for:
{{#each ./testimonials}}
<li class="triggerClass videoPopup" {{data "testimonial"}} ($click)="clickHandler(./isPopUpOpen)">`.
{{/each}}
Kevin Phillips
@phillipskevin
Jul 24 2017 21:34
what isn't working?
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 21:40
oh nm, just misspelled variable, my bad
Kevin Phillips
@phillipskevin
Jul 24 2017 21:45
ok good
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 21:58

just fyi, this is the code I settled on as replacement

<li class="triggerClass videoPopup" ($click)="setIsPopupOpen(%context)">

%context lets me update viewModel by just assigning value, whereas passing ./isPopupOpen did not

Kevin Phillips
@phillipskevin
Jul 24 2017 22:02
you're trying to update the isPopupOpen property?
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 22:02
yeah
Kevin Phillips
@phillipskevin
Jul 24 2017 22:07
that's because javascript is pass-by-value... so you can't change the value of the boolean
if you want, you can use ($click)="setIsPopupOpen(~./isPopupOpen)"
which will turn isOpenPopup into a compute
so you can get / set it like isOpenPopup(true)
Ranjan Subbiah
@ranjanbuilds
Jul 24 2017 22:18
awesome, thanks Kevin
Kevin Phillips
@phillipskevin
Jul 24 2017 22:22
yeah, for sure