These are chat archives for canjs/canjs

19th
Jan 2017
Thomas Sieverding
@Bajix
Jan 19 2017 02:17
What's wrong with this set algebra? I want it to be included if both sets have the same prop values, otherwise excluded. So something such as { a: 5, b: 3 } shouldn't match { a: 5 }
function( aVal, bVal, a, b, prop, algebra ) {
  if (a[prop] === b[prop]) {
    if (aVal === b[prop]) {
      return {
        intersection: aVal
      };
    }
  }

  return {
    difference: aVal
  };
}
I want to omit results matching a=5 & b=3 from sets with a=5
Sunil George
@georgesunil81
Jan 19 2017 19:56
I have a quick question regarding CanJS models. I need to merge the responses from to or more API calls and return them as a single response. Specifically, once I get the response from API-A, I want to parse the response and make a call to API-B for each of the response-records from API-A. I was thinking of using parsemodels for this. Anyone has any ideas or come across this need? Please let me know.
Gira Minus
@gKreator
Jan 19 2017 20:13
Canjs 3?
Sunil George
@georgesunil81
Jan 19 2017 20:14
Canjs 2.3.24
Gira Minus
@gKreator
Jan 19 2017 20:17
honestly the best thing to do instead of having a possibility of 100 ajax calls happening... just have your api spit out the model pre factored
/api/a/?include_api_b=1
Sunil George
@georgesunil81
Jan 19 2017 20:26
@gKreator that is the issue. I have no control over the backend. They are fine with 100 calls happening though (I made sure that they know that).
So now, I am trying to figure out how to do it in CanJS
Let me know if you have any ideas?
Gira Minus
@gKreator
Jan 19 2017 20:27
yeah happens
pretty much just write your own callback for the findAll function and have all your ajax calls there... just be careful with all the deffered methods
Sunil George
@georgesunil81
Jan 19 2017 20:30
Ah @gKreator, thanks for the link, it looks like it will allow merging across APi calls.
Chasen Le Hara
@chasenlehara
Jan 19 2017 21:38
@Bajix, did you figure out the set algebra?
Thomas Sieverding
@Bajix
Jan 19 2017 21:38
No, it didn’t seem like difference was working
Chasen Le Hara
@chasenlehara
Jan 19 2017 21:38
cc @justinbmeyer
Matthew Phillips
@matthewp
Jan 19 2017 21:39
@roemhildtg Don't know the performance diff, probably very little.
They are two templates, one calls the other like a function.
I wouldn't worry about it.
Gregg Roemhildt
@roemhildtg
Jan 19 2017 21:39
Okay cool

Lets say I have an object

var obj = new can.DefineMap();
obj.hello = 'hey';
var prop = 'name';
obj[prop] = 'john';

how can I get a plain object with those properties?

Matthew Phillips
@matthewp
Jan 19 2017 21:44
with name and hello?
obj.get()
Gregg Roemhildt
@roemhildtg
Jan 19 2017 21:44
I don't think that works though since I'm not defining those properties using extend
Matthew Phillips
@matthewp
Jan 19 2017 21:44
v true
Gregg Roemhildt
@roemhildtg
Jan 19 2017 21:49
would canjs/can-define#63 help with this?
Gira Minus
@gKreator
Jan 19 2017 21:52
Try serialize?
Gregg Roemhildt
@roemhildtg
Jan 19 2017 21:53
nope, both just output an empty object it seems http://jsbin.com/fanawagoma/edit?html,js,console
Matthew Phillips
@matthewp
Jan 19 2017 21:57
why do you need a plain object?
Gregg Roemhildt
@roemhildtg
Jan 19 2017 21:58
I'm serializing it to json
to get a string
I could keep a copy of the values set in a plain object
Have one observable value and one value with a plain object
Kevin Phillips
@phillipskevin
Jan 19 2017 22:00
you can’t define the values ahead of time?
or use a can.Map
Gregg Roemhildt
@roemhildtg
Jan 19 2017 22:02
Not in a way that I can think of, the properties on the DefineMap are set dynamically on the viewmodel
I could use can.Map, so you mean with property.attr, right? I had forgotten about that :smile:
Kevin Phillips
@phillipskevin
Jan 19 2017 22:03
or serialize
Gregg Roemhildt
@roemhildtg
Jan 19 2017 22:05
I'll probably go that route, thanks!
Kevin Phillips
@phillipskevin
Jan 19 2017 22:06
no problem
Gregg Roemhildt
@roemhildtg
Jan 19 2017 22:07
do you think this capability will eventually be added to DefineMap?
Kevin Phillips
@phillipskevin
Jan 19 2017 22:08
actually, you can just use set on DefineMap
same as how you’d have to use attr to set the values on a can.Map
then the properties will be serialized as you’re expecting
Gregg Roemhildt
@roemhildtg
Jan 19 2017 22:09
Ah, that makes sense. Yes, it is the same as attr
and that works since using property.newProp = 'value' doesn't run notify the definemap that the keys were changed?
or something to that effect
Kevin Phillips
@phillipskevin
Jan 19 2017 22:14
yeah, it sets it up as if you defined it in DefineMap.extend
Gregg Roemhildt
@roemhildtg
Jan 19 2017 22:15
Gotcha.
Kevin Phillips
@phillipskevin
Jan 19 2017 22:17
you just need to use set when adding a new property (if you know that)
this kind of thing works:

var obj = new can.DefineMap();

obj.set('hello', 'hey');
var prop = 'name';
obj.set(prop, 'john');
obj[prop] = 'mark';

console.log(obj.serialize());
the serialized value will have name: "mark"
Gregg Roemhildt
@roemhildtg
Jan 19 2017 22:17
Yup, that makes sense