These are chat archives for canjs/canjs

4th
Apr 2016
Thomas Sieverding
@Bajix
Apr 04 2016 00:51
You made a PR?
Christopher Oliphant
@RALifeCoach
Apr 04 2016 01:02
No, I have not created a PR. I can if it would make sense.
Thomas Sieverding
@Bajix
Apr 04 2016 01:02
That’s how this works
Christopher Oliphant
@RALifeCoach
Apr 04 2016 01:11
I am new to this. I made my changes on a fork. Should I remake them on a branch from the unforked code?
Christopher Oliphant
@RALifeCoach
Apr 04 2016 12:08
The PR has been created
Christopher Oliphant
@RALifeCoach
Apr 04 2016 16:32

@Bajix You have been recommending can.compute as a way of improving performance. I have the following situation:

can.Map.extend({
  defines: {
    player: { Type: Player },
    parent: {type: ‘*’ } // is a pointer to the parent module
  },
  playerComputed Value: function () {
    return this.parent.someMethod(this.attr(‘player’));
  }
};

My questions:

  1. Would it make sense to make playerComputeredValue a compute?
  2. The parent method (someMethod) only uses 2 properties from the player object. Is there some way of telling CanJS to only recompute playerComputedValue when only those properties change on player?

A general question: I have a stache template the looks something like:

{{#method1()}}{{/method1}}{{#method1()}}{{/method1}}

Does the CanJS code generate one observable for method1 or two?

dylanrtt
@dylanrtt
Apr 04 2016 19:20
@RALifeCoach If you define playerComputed as a compute with get(), it will recompute when any of its dependencies change (observables read during its execution)
Christopher Oliphant
@RALifeCoach
Apr 04 2016 19:23
@dylanrtt yes, but will it be faster than not defining it as a compute? My testing suggests using can.compute makes the overall execution time slower.
dylanrtt
@dylanrtt
Apr 04 2016 19:25
It depends on the exact use case. Computes can slow things down due to the bindings but sometimes reading a compute whose value is cached is faster than running a method every time.
I think methods in this case are computized by stache. That is, all the observables read during the method execution will be observed in order to redraw the view
Christopher Oliphant
@RALifeCoach
Apr 04 2016 19:28
They do seem to be computed and they seem to run faster than if I code the can.compute.
seasoup
@seasoup
Apr 04 2016 21:54
Hey, can.route messes up my routing if I have a search param ?fixtures=true because in the route.js file it does can.route.data.serialize() which url encodes the ? and turns the url from http://localhost:8126/dashboard?fixtures=true into http://localhost:8126/?dashboard%2F%3Ffixtures=true any idea how to fix this?
Thomas Sieverding
@Bajix
Apr 04 2016 22:25
@RALifeCoach Computes have built in memoization by virtue of caching, but you only get a benefit from this if you’re actually avoiding expensive calls

The parent method (someMethod) only uses 2 properties from the player object. Is there some way of telling CanJS to only recompute playerComputedValue when only those properties change on player?

Any property access via .attr or compute called with be tracked automatically, and be bound to

If you did this.attr(‘parent’), and passed in this.attr(‘player’), those would both be tracked
The parent & player properties of this that is, not the properties of those objects
Matthew Phillips
@matthewp
Apr 04 2016 22:28
Thanks @Bajix @dylanrtt and everyone for being so helpful in answer questions here!
Glad to see such a nice community forming
Thomas Sieverding
@Bajix
Apr 04 2016 22:29
Anytime @matthewp
If you ever make it to LA, we should co-host a meetup
Matthew Phillips
@matthewp
Apr 04 2016 22:34
I believe Justin is doing some DoneJS meetups in LA
Thomas Sieverding
@Bajix
Apr 04 2016 22:35
I know. I’m co-organizer of said meetup group
Matthew Phillips
@matthewp
Apr 04 2016 22:36
oh, cool
Thomas Sieverding
@Bajix
Apr 04 2016 22:37
I’ve only hosted two meetups so far; One when Justin flew into town, and another when we hired Brian to consult
I no longer work at the company that was hosting, and they’ve been relatively hostile, so we’ve been SOL lately
Need a new venue really badly