Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:01
    m-mujica synchronize #5303
  • 15:01

    m-mujica on upgrade-deps

    Update bundlesize threshold for… (compare)

  • 14:14
    pehaada starred canjs/canjs
  • 14:11
    m-mujica synchronize #5303
  • 14:11

    m-mujica on upgrade-deps

    Update bundlesize threshold for… (compare)

  • 14:02
    phillipskevin commented #5303
  • 12:08
    m-mujica edited #5119
  • 12:08

    m-mujica on upgrade

    (compare)

  • 12:07

    m-mujica on major

    Upgrade routing guide to Can 6 Fix incorrect highlight Use svg images (instead of .png) and 1 more (compare)

  • 12:07
    m-mujica closed #5302
  • 12:07
    m-mujica commented #5302
  • 11:50
    esteverodriguez starred canjs/canjs
  • Sep 21 21:15
    greenkeeper[bot] commented #5237
  • Sep 21 21:15

    greenkeeper[bot] on @feathersjs

    chore(package): update @feather… (compare)

  • Sep 21 21:12
    greenkeeper[bot] commented #5236
  • Sep 21 21:12

    greenkeeper[bot] on @feathersjs

    chore(package): update @feather… (compare)

  • Sep 21 03:58

    greenkeeper[bot] on @octokit

    (compare)

  • Sep 21 03:57

    greenkeeper[bot] on @octokit

    chore(package): update @octokit… (compare)

  • Sep 20 21:04
    m-mujica commented #5303
  • Sep 20 20:23
    m-mujica opened #5303
Adam Tourkow
@atourkow
So, like in the viewmodel is a function called updateStuff that calls the model?
Kevin Phillips
@phillipskevin
the most basic way is to use the model to initialize your viewmodel
so you have a property on your viewModel that represents whatever data is returned by the Model
in that example, the players property ends up being a promise
Another nice way to do it is to have two separate properties - one for the promise and one for the data
so that uses the asynchronous getter to set game to be the data returned by Game.get
that’s nice because you can use the promise in your template, but also use the data
Adam Tourkow
@atourkow
I get the init, but does that also include updating?
Kevin Phillips
@phillipskevin
like:
{{#if gamePromise.isResolved}}
    {{#game.homeTeam.score}} - {{#game.awayTeam.score}}
{{/if}}
yes, if you use the get: function(last, set){ approach, it would update whenever gamePromise changes
that getter sets up binding so that if it changes, the template will update
if you use value it’s just setting the intitial value, so it won’t handle updates
Adam Tourkow
@atourkow
So, you can just call viewModel.get() to refresh from ajax?
Kevin Phillips
@phillipskevin
if your template uses game that will happen automatically
viewModel.attr(‘game’) calls that get()
but what you’ll need to do in your case is set up some way that gamePromise will return a new promise after some amount of time
I would try something like this:
define: {
  gamePromise: {
    get: function() {
      return this.getGamePromise();

      setTimeout(this.getGamePromise, 5000);
    }
  }
},
getGamePromise: function() {
  return Game.get({...})
}
hmm, that’s not going to work… because it won’t change the return value of gamePromise
let me try it in a JSBin
Adam Tourkow
@atourkow
It seems like there's a lot of ways to do things in canJS.
Mohamed Cherif Bouchelaghem
@cherifGsoul
@atourkow you may look at can-connect it does cool stuffs around ajax
Adam Tourkow
@atourkow
@cherifGsoul ok
Kevin Phillips
@phillipskevin
define: {
  gamePromise: {
    get: function(val, set) {
     this.getGamePromise().then(set);

      setTimeout(function() {
        this.getGamePromise().then(set);
      }, 5000);
    }
  }
},
getGamePromise: function() {
  return Game.get({...})
}
I’m still going to put together a jsbin, but I think that should work
Kevin Phillips
@phillipskevin
@atourkow that code above works if you only want to update once, so doesn’t solve your problem
here’s an example of updating the model every 1 second: http://jsbin.com/hamidalugi/edit?html,js,output
let me know if any of that doesn’t make sense
Adam Tourkow
@atourkow
@phillipskevin Thanks!
Kevin Phillips
@phillipskevin
no problem, hope it helped
Adam Tourkow
@atourkow
We'll see. gotta try it first
Here's a stupid question: I don't have the whole page as a view, so what's the best way to just put in a component? After defining the component, just make new template = can.stache('<mycomponent/>'); $('#elIWantMyComponentIn').append(template());
Kevin Phillips
@phillipskevin
you could also checkout can.autorender
Adam Tourkow
@atourkow
ok
Kevin Phillips
@phillipskevin
that way you could just put you stache script inside of #elIWantMyComponentIn and can would render it for you
Adam Tourkow
@atourkow
oh, how interesting
Kevin Phillips
@phillipskevin
but before that existed, we did it with basically the code you wrote
Adam Tourkow
@atourkow
@phillipskevin are you a canJS Dev?
Kevin Phillips
@phillipskevin
yeah, I’m a developer at Bitovi
so primarily do consulting with CanJS and our other tools
Adam Tourkow
@atourkow
@phillipskevin nice. I wish the word would spread more about canJS. I keep looking at other technlogies, bt find I like the way CanJS works the best
Kevin Phillips
@phillipskevin
Yeah, I hear you
we talk at a lot of meetups and conferences
Adam Tourkow
@atourkow
where are you based?
Kevin Phillips
@phillipskevin
if there’s a group in your area that you think it would be good for us to talk at, let us know
we work remotely, so we’re all over
Adam Tourkow
@atourkow
I've stopped doing coding for money, this is for my personal site. But, I'll definitely promote.
I still talk to devs all the time and meetups