These are chat archives for canjs/canjs

15th
Mar 2018
andre-cgn
@andre-cgn
Mar 15 2018 11:42
in case you guys are intersted. i now found out what my probem was. since i am currently rather creating a PROC, I didn't feel the necessity to create git repos for all the packages. so i consumed my can-stache-helper-lib like: npm install --save ../my-dependency.
that lead to the problem, I described earlier
if i put my helper dependency into a repo and npm install https:/gitrepo, everything works nicely
so the problem really was git vs. local npm install
i have no idea why but maybe that is something thats good to know
Kevin Phillips
@phillipskevin
Mar 15 2018 14:59
We have a new Forms Guide on canjs.com. I wrote up some of the highlights: https://forums.donejs.com/t/canjs-forms-guide/821. Take a look at the post and the guide. Would love to hear what you think.
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:32
get (val, set) {
       // why does console.log(val) always return undefined?
       // I want to prevent this from making a new request if we've already made this request
        UserRole.getList({user_id: this.id})
          .then(roles => {
            set(roles.map(role => {
              return role.role_name;
            }));
          });
      }
How can I keep the getter from making a new request if we've already resolved it?
Kevin Phillips
@phillipskevin
Mar 15 2018 19:34
val is the last set value
so it is only defined if that property was set
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:34
So not the set val from a getter
Kevin Phillips
@phillipskevin
Mar 15 2018 19:34
right
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:35
Gotcha. I keep getting confused by that
Kevin Phillips
@phillipskevin
Mar 15 2018 19:35
but if that property is bound, the value should be cached
so you should not have to worry about preventing a duplicate request
it should happen automatically
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:35
I think that if it gets bound in multiple places it gets called again
Like I have a user login component that checks the username, login etc, and I have some other components that get rendered in that call it.
But I think I solved it using the rolesPromise getter and a roles getter
Kevin Phillips
@phillipskevin
Mar 15 2018 19:36
checks the username, login etc
in javascript?
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:36
Its in stache
Well, there's some javascript too
I guess so both
Kevin Phillips
@phillipskevin
Mar 15 2018 19:37
by "bound" I mean something that calls .on
or canReflect.onKeyValue
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:37
Oh, so no, I'm not actually calling that directly
Kevin Phillips
@phillipskevin
Mar 15 2018 19:37
var VM = Can.DefineMap.extend({
  foo: {
    get: function() {

    }
  }
})

var vm = new VM();

vm.foo; // not bound

vm.on('foo', function() {}); // bound
stache will do it for you
if you're using that property in stache
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:39
and this one:
var otherVm = can.DefineMap.extend({ prop: get(){ return vm.foo; });
A view model with a getter that uses another vm's getter
Kevin Phillips
@phillipskevin
Mar 15 2018 19:42
only if otherVM.prop is bound
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:42
ok
uncomment the .on
to see the difference
Gregg Roemhildt
@roemhildtg
Mar 15 2018 19:44
Oh, yeah I see the difference