These are chat archives for canjs/canjs

5th
Apr 2016
Thomas Sieverding
@Bajix
Apr 05 2016 01:44
Can reference scope be used in conjunction w/ expressions? Previously I’ve done ($click)=“attr(‘foo’, ‘bar’)”, however I’m not sure how to do the equivalent with template reference variables
dylanrtt
@dylanrtt
Apr 05 2016 04:08
@Bajix Generally, yes. You can do ($click)=“attr('foo', *bar)” assuming *bar is in the ref scope
Thomas Sieverding
@Bajix
Apr 05 2016 04:09
Yea but attr would be the current scopes map
dylanrtt
@dylanrtt
Apr 05 2016 04:10
I'm not sure I understand the problem
Thomas Sieverding
@Bajix
Apr 05 2016 04:10
I want to set *foo with a click handler
I’d like to do so on the template reference rather than the current scope context
dylanrtt
@dylanrtt
Apr 05 2016 04:13
Hmm, I don't think that's possible yet. You can call a method of *foo though
Thomas Sieverding
@Bajix
Apr 05 2016 04:14
Mmmm
I feel like it would’ve been maybe more useful to just do *.foo
Have * be an empty map
That way you always access it’s methods
dylanrtt
@dylanrtt
Apr 05 2016 04:27
Here is a solution if you don't mind the extra verbosity http://jsbin.com/hagejaloxi/edit?html,js,output
Thomas Sieverding
@Bajix
Apr 05 2016 04:35
Could that just do %.root.attr(‘*foo’, ‘bar’)?
or %scope.attr(‘*foo’, ‘bar’)
dylanrtt
@dylanrtt
Apr 05 2016 04:44
scope.attr() works in the method but for some reason I couldn't get it to work in the expression
Thomas Sieverding
@Bajix
Apr 05 2016 04:45
Hmmm possible bug?
I’ve noticed call expressions struggle w/ promises
You can’t do $(click)=“post.save().then(@redirect, @handleError)"
But I suppose ($click)”="post.save(@redirect, @handleError)” might work
dylanrtt
@dylanrtt
Apr 05 2016 04:51
yeah there might be some bugs because it's pretty new
Christopher Oliphant
@RALifeCoach
Apr 05 2016 11:04

I have another performance question. I have a large stache template that creates one row of a div table. There are 156 rows to the entire table. The entire table is loaded and then reloaded as the page is loaded. The load takes about 4 seconds which isn’t great, but I can live with. The reload varies as shown below.

this.attr('player', player);

reloads in 1.5 seconds

            if (this.attr('player')) {
                this.attr('player').attr(player);
            } else {
                this.attr('player', player);
            }

reloads in 4 seconds. Yet I was told the this was the better way to go.

Gregg Roemhildt
@roemhildtg
Apr 05 2016 13:51
Good morning. If I have a virtual property using the define get function, can I set it up in a way that it builds a new object the first time its accessed and subsequent times it only modifies the existing object, rather than creating a brand new object? I have a template that uses this object and i'd like it to not have to re-render the entire template each time the object's dependents change.
Christopher Oliphant
@RALifeCoach
Apr 05 2016 13:52
How do you build the new object? What do you do with the new object when it’s built?
Gregg Roemhildt
@roemhildtg
Apr 05 2016 13:59
The new object is a something like this and it is used to render a form:
this.attr('fields').forEach(function(fieldname){
   newObj[fieldname] = {
      alias: self.formatField(fieldname),
      value: self.attr('formObject' + '.' + fieldname),
      //other field properties
   };
});
At the moment, I'm basically returning the newObj property, from the get function
Christopher Oliphant
@RALifeCoach
Apr 05 2016 14:02
Use a switch: if (!this.objectBuilt) { build; this.objectBuilt = true;}
Gregg Roemhildt
@roemhildtg
Apr 05 2016 14:06
I was trying to set it up like that, at the beginning of the get function, I would check to see if there was a lastSetValue.
get: function(lastValue){
  if(lastValue){
   //modify and return lastValue
} else { /* build new value */}
But lastValue is always undefined
Christopher Oliphant
@RALifeCoach
Apr 05 2016 14:07
using this.lastValue would work. So would this.attr(‘this field name’, object);
place that after building the object
Gregg Roemhildt
@roemhildtg
Apr 05 2016 14:11
I should use this.attr('fieldName', newValue); instead of returning the object?
Christopher Oliphant
@RALifeCoach
Apr 05 2016 14:12
This is a getter, not a setter
Gregg Roemhildt
@roemhildtg
Apr 05 2016 14:12
Yes
Christopher Oliphant
@RALifeCoach
Apr 05 2016 14:13
Returning a value in a getter won’t set the value. That only works in a setter.
Gregg Roemhildt
@roemhildtg
Apr 05 2016 14:17
Okay, that makes sense. One more question, the getter should still return the object, correct? return this.attr('thisFieldName') after setting the value
Christopher Oliphant
@RALifeCoach
Apr 05 2016 14:18
Returning the object makes it available to the code trying to use the object.
Gregg Roemhildt
@roemhildtg
Apr 05 2016 14:26
Okay thanks. That helps
Christopher Oliphant
@RALifeCoach
Apr 05 2016 14:28
good
Christopher Oliphant
@RALifeCoach
Apr 05 2016 17:53
Hello all - I need some help with unit testing
Kevin Phillips
@phillipskevin
Apr 05 2016 18:22
are you running into an issue?
Christopher Oliphant
@RALifeCoach
Apr 05 2016 18:25
Yes I am
I am trying to execute a method in the view model, via the component
I can get the viewModel using $el.viewModel()
but I can’t execute $el.viewModel().someMethod()
I can see and update properties via $el.viewModel().xxx
ericcarino
@ericcarino
Apr 05 2016 18:30
can.grep() Why is it that I cannot find any documentation on this function?
Kevin Phillips
@phillipskevin
Apr 05 2016 18:30
@RALifeCoach what happens when you try to execute the method?
Christopher Oliphant
@RALifeCoach
Apr 05 2016 18:30
The method is undefined
Curtis Cummings
@ccummings
Apr 05 2016 18:32
@ericcarino can aliases jQuery utility methods. Check out http://api.jquery.com/jquery.grep/
Christopher Oliphant
@RALifeCoach
Apr 05 2016 18:38
it is working in JSBin
(I should have checked there first)
Kevin Phillips
@phillipskevin
Apr 05 2016 18:39
can you share the bin?
Now I have to figure out why it’s not working in my unit test
ericcarino
@ericcarino
Apr 05 2016 18:51
@ccummings Thanks!