by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Sep 29 13:17
    ko25july starred canjs/canjs
  • Sep 21 17:41
    cherifGsoul assigned #5508
  • Sep 21 17:39
    cherifGsoul opened #5508
  • Sep 18 19:32
  • Sep 11 02:59
    torongu starred canjs/canjs
  • Sep 09 06:57
    tbreuss starred canjs/canjs
  • Sep 04 18:58
    cherifGsoul review_requested #5507
  • Sep 04 18:58
    cherifGsoul opened #5507
  • Sep 04 18:51

    cherifGsoul on post-release-script

    Add GitHub release automation (compare)

  • Aug 22 17:54
    ThisIsntMyId starred canjs/canjs
  • Aug 21 08:54
  • Aug 20 20:24
    ktitaro starred canjs/canjs
  • Aug 17 16:53
  • Aug 17 16:51
    kuustudio starred canjs/canjs
  • Aug 14 17:12
    cherifGsoul closed #5494
  • Aug 14 17:07
    cherifGsoul labeled #5490
  • Aug 14 17:05
    cherifGsoul labeled #5492
  • Aug 14 17:04
    cherifGsoul closed #5495
  • Aug 14 17:04
    cherifGsoul closed #5498
  • Aug 13 07:25
    kitoki starred canjs/canjs
Thomas Sieverding
@Bajix
np
Christopher Oliphant
@RALifeCoach
One question - would take the returned value from parseModel and use it to instantiate a Map or Model?
Thomas Sieverding
@Bajix
re: infinite loop, you need to set the value to the result of calling model
So if (foo.bar) { foo.bar = Bar.model(foo.bar) }
Christopher Oliphant
@RALifeCoach
I have var data = Model.model(request);
I then say, playerRowMap = new Model(data);
Thomas Sieverding
@Bajix
parseModel: function( data, xhr ) {
  if (typeof data === 'string') {
    return {
      _id: data
    };
  }

  var __v = data.__v,
    _id = data._id;

  if (_id && typeof __v === 'number' && Channel.store.hasOwnProperty(_id)) {
    var channel = Channel.store[_id];

    if (channel.__v > __v) {
      delete data.__v;
      delete data.userCount;
      delete data.guestCount;
    }
  }

  can.batch.start();

  [
    'moderators',
    'bannedUsers',
    'bootedUsers'
  ].forEach(function( key ) {
    if (data.hasOwnProperty(key)) {
      data[key] = User.models(data[key]);
    }
  });

  if (data.owner) {
    can.extend(data.owner, {
      isModerator: true,
      isOwner: true
    });

    data.owner = User.model(data.owner);
  }

  can.batch.stop();

  return data;
},
Use it like that
Christopher Oliphant
@RALifeCoach
that doesn’t answer my question
Thomas Sieverding
@Bajix
No that’s not how it works
model returns an instance
Christopher Oliphant
@RALifeCoach
instance of?
Thomas Sieverding
@Bajix
And you don’t pass it the promise, you pipe it the AJAX request
Christopher Oliphant
@RALifeCoach
Model?
Thomas Sieverding
@Bajix
yes
Christopher Oliphant
@RALifeCoach
I DON’T HAVE AJAX
I have said that so many times now.
Thomas Sieverding
@Bajix
Whatever the data source is, doesn’t matter, I was giving you an example
Christopher Oliphant
@RALifeCoach
I have a player object - that’s it
Thomas Sieverding
@Bajix
var playerRowMap = PlayerRowMap.model(myDataPJSO)
That’s it
Christopher Oliphant
@RALifeCoach
okay
Thomas Sieverding
@Bajix
playerRowMap instanceof PlayerRowMap === true
Christopher Oliphant
@RALifeCoach
alright - that worked and is better timing then my last attempt
however, the updating is still taking a while
Thomas Sieverding
@Bajix
One issue at a time
Christopher Oliphant
@RALifeCoach
alright then suggest how best I update the model for maximum efficiency
I will read your response in the morning
Thomas Sieverding
@Bajix
1) Pass around map instances instead of cross-binding properties to components
2) Use one-way binding whenever applicable
3) Use leakScope: false whenever applicable
4) Use ./ within your bindings
Thomas Sieverding
@Bajix
5) Use computes like a mad man. The goal is to lower unnecessary change events. For example, the isAdmin getter I described above is actually really performant, as now I can bind to it elsewhere, and something like changing users or logging in that would trigger isAdmin to be re-computed wouldn’t trigger other computes that are dependent on isAdmin from re-computing if isAdmin doesn’t change
isAdmin: {
  get: function() {
    var profile = this.attr('profile');

    if (profile) {
      return profile.attr('tier') === config.tiers.indexOf('admin');
    }

    return false
  }
}
Changing profile / tier would recompute this. But if the value hasn't changed, computes dependent on this wouldn't recompute
Julian
@pYr0x
@Bajix you mean, that computes are cached...?
how look like the worse isAdmin method?
Christopher Oliphant
@RALifeCoach
@pYr0x parseModel isn’t producing any better results than simply using type: ‘*’ for objects not needing observables
Julian
@pYr0x
ok.. and what about the point 5) bajix said?
also 3) and 4) are good points
to look at
Christopher Oliphant
@RALifeCoach
computes give a way to handle events outside of the component when attributes within the map associated with the component change
I don’t really have a need for that
When I turned on leakScope - everything stopped working
All my data is in the viewModel, not in the outer scope
I haven’t tried ./ and I must confess I am not sure what that means
I don’t recall seeing that in the docs
Christopher Oliphant
@RALifeCoach
@pYr0x can you please point to the docs for ./
Jeroen Cornelissen
@jeroencornelissen
Christopher Oliphant
@RALifeCoach
Thanks
Kevin Phillips
@phillipskevin
@RALifeCoach one thing I would test is how much of the DOM is being updated when you make a change