These are chat archives for canjs/canjs

31st
Mar 2017
Christopher Baker
@christopherjbaker
Mar 31 2017 00:13
What am I doing wrong here? Console logs on resolution, but fragment does not update.
https://gist.github.com/christopherjbaker/750a91694cddecfbfb2971b25adfaca9
Kevin Phillips
@phillipskevin
Mar 31 2017 00:16
you can’t return the Promise and also use setVal
so you can either make it two separate properties
or just return the Promise and use {{#each foos.value}} in your template
Christopher Baker
@christopherjbaker
Mar 31 2017 00:24
I was sure I had tried that. Thank you =]
Kevin Phillips
@phillipskevin
Mar 31 2017 00:25
a lot of times we’ll separate it in to differnt properties
Christopher Baker
@christopherjbaker
Mar 31 2017 00:26
What is the benefit to htat?
Kevin Phillips
@phillipskevin
Mar 31 2017 00:26
so you can use the isResolved and other helpers
but not use .value everywhere
in the template
Christopher Baker
@christopherjbaker
Mar 31 2017 00:28
The in-depth guide is next on my list
Kevin Phillips
@phillipskevin
Mar 31 2017 00:30
:+1:
are you going through the donejs-next versions?
Christopher Baker
@christopherjbaker
Mar 31 2017 00:33
no, just the ones at donejs.com
Kevin Phillips
@phillipskevin
Mar 31 2017 00:34
ok, cool, those are good too :wink:
Christopher Baker
@christopherjbaker
Mar 31 2017 00:35
setVal can be used in leu of a promise?
Kevin Phillips
@phillipskevin
Mar 31 2017 00:37
yeah
can be used to get any kind of async value
Christopher Baker
@christopherjbaker
Mar 31 2017 00:37
it is firing the listener, but not rerendering
Kevin Phillips
@phillipskevin
Mar 31 2017 00:38
isResolved and .value are specific to promises
sorry if I misunderstood what you were asking
Christopher Baker
@christopherjbaker
Mar 31 2017 00:39
(working now)
Kevin Phillips
@phillipskevin
Mar 31 2017 00:39
cool
Nitin Pasumarthy
@Nithanaroy
Mar 31 2017 08:16
Whats the equivalent of "change" event for a DefineList in CanJS 3?
var list = new can.List(['Alice', 'Bob', 'Eve']);
list.bind('change', function() { console.log('An element changed.'); });
Szabolcs Schmidt
@sszabolcs
Mar 31 2017 09:56

Hi!

Is there a way in CanJS 3 to listen for map attribute changes with templated event handler functions?
I would like to do something like this:

var myMap = can.DefineMap.extend({
   foo: { type: "string" },

  "{foo} change": () {
      console.log("foo changed");
   }
})

Or should I write a custom set() method for this property?

Jeroen Cornelissen
@jeroencornelissen
Mar 31 2017 10:05
@sszabolcs don’t think that exist. You can listen to property like this : myMap.on(‘foo’, function(….
@Nithanaroy change event doesn’t exist in CanJS 3.
You can listen to add, remove and length or a custom property.
See : http://canjs.com/doc/can-define/list/list/AddEvent.html
Szabolcs Schmidt
@sszabolcs
Mar 31 2017 11:11
@jeroencornelissen thanks!
Kevin Phillips
@phillipskevin
Mar 31 2017 11:35
@sszabolcs if you use this.foo in a getter of another property, that getter will automatically re-run when foo changes
Szabolcs Schmidt
@sszabolcs
Mar 31 2017 11:43
@phillipskevin thanks!
Juan Orozco
@Macrofig
Mar 31 2017 15:12
How do I tell can-set to ignore $limit?
Christopher Baker
@christopherjbaker
Mar 31 2017 15:32
The foos event is called, but the bars is not. Is that the correct behaviour?
http://jsbin.com/woruvac/edit?js,console,output
Gregg Roemhildt
@roemhildtg
Mar 31 2017 16:17
@Macrofig does this work?
const algebra = new set.Algebra(
    '$limit': function(){
        return true;
    }
);
Nitin Pasumarthy
@Nithanaroy
Mar 31 2017 17:21
@jeroencornelissen Then how can I listen when list[0] changes?
Nitin Pasumarthy
@Nithanaroy
Mar 31 2017 17:39

Created an example showing when list changes do not trigger an event! https://jsbin.com/toyogo/edit?html,js,output

Also asked the question there itself

Kevin Phillips
@phillipskevin
Mar 31 2017 17:56
why are you worried about extra events @Nithanaroy ?
Nitin Pasumarthy
@Nithanaroy
Mar 31 2017 18:42
Extra events are fine. It would be nice if I can listen on list changed event mainly.
Kevin Phillips
@phillipskevin
Mar 31 2017 18:42
what do you want to do when it changes?
Kevin Phillips
@phillipskevin
Mar 31 2017 18:48
you can just create another property that calls this.list.serialize() and listen to that
but depending on what you’re trying to do, there are probably much more performant ways to do it
Gregg Roemhildt
@roemhildtg
Mar 31 2017 19:08

Added support for {{ foo["bar.baz"] }} in can-stache

@phillipskevin I was just wondering about this today, and I found this. Am I right in assuming that foo.bar.baz will be printed (if it exists)?

Justin Meyer
@justinbmeyer
Mar 31 2017 19:17
@sszabolcs I'd suggest checking out can-define-stream
it can help you do what you want
Kevin Phillips
@phillipskevin
Mar 31 2017 19:21
@roemhildtg the thing I fixed is for when you have a property with a dot in it… like:
new CanMap({
    'bar.baz': 'Hello World'
});
if you want foo.bar.baz, you wouldn’t need the Bracket notation
Gregg Roemhildt
@roemhildtg
Mar 31 2017 19:48
Oh I see, I was looking at it like this: {{ foo[propName] }} where propName = 'bar.baz'
Would give me foo.bar.baz. But that wouldn't really make sense
I could always use a helper to do that
Nitin Pasumarthy
@Nithanaroy
Mar 31 2017 20:37

@phillipskevin Thanks.

var obj1.obj2.list = [{key: "key1", value: "variable_value"}]

I want to set another field on ViewModel DefineMap, whenever variable_value changes above. Also the obj1 is passed to the component via one-way binding

Juan Orozco
@Macrofig
Mar 31 2017 20:44
@roemhildtg Thanks! That got me a step further. I still have a problem where if sockets will ignore the $limit property. I guess I meant that I want can-set to not compare items with $limit.