These are chat archives for canjs/canjs

12th
Dec 2016
Justin Meyer
@justinbmeyer
Dec 12 2016 20:53
@gsmeets I'll talk to @daffl about when we might be able to make a new release
Chasen Le Hara
@chasenlehara
Dec 12 2016 20:56
@justinbmeyer, we published can@2.3.28 last week
Justin Meyer
@justinbmeyer
Dec 12 2016 21:01
oh :-)
Thomas Sieverding
@Bajix
Dec 12 2016 21:02
@justinbmeyer feedback on canjs/can-define#100 ?
I can start on a solution
Justin Meyer
@justinbmeyer
Dec 12 2016 21:14
@Bajix currently, .get should return the same properties as .serialize() would
though it should not return the result of calling the defined serialize method
ideally ... there should be an enumerable behavior
Thomas Sieverding
@Bajix
Dec 12 2016 21:15
So previously they worked differently, and get was all enumberable propers whereas serialize was all props that are enumberable & serializeable
Justin Meyer
@justinbmeyer
Dec 12 2016 21:16
@Bajix they worked the same afaik
Thomas Sieverding
@Bajix
Dec 12 2016 21:16
This was really useful for a lot of use cases
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:16
maybe there is space for a can-define-????
where it works like @Bajix suggests it
Justin Meyer
@justinbmeyer
Dec 12 2016 21:16
@Bajix maybe add some cases in the example
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:17
that should easy do able as it worked this way
Justin Meyer
@justinbmeyer
Dec 12 2016 21:17
that make the case where can-define and can-map-define work differently
Thomas Sieverding
@Bajix
Dec 12 2016 21:18
So it wasn’t intentional that attr previously would add props that wouldn’t normally be serialized?
Justin Meyer
@justinbmeyer
Dec 12 2016 21:18
to make sure we are on the same page ...
var map = new can.Map();
map.attr("propA", "valueA");
map.serialize() //-> {propA: "valueA"}
that is what I think the behavior was in 2.3 and is in 3.0 for can-map
var map = new can.Map();
map.attr("propA", "valueA");
map.attr() //-> {propA: "valueA"}
attr would do the same thing
So that’s just a test demoing it
Justin Meyer
@justinbmeyer
Dec 12 2016 21:21
yes, that same behavior worked for can.Map
in 2.3 as well
(afaik)
Thomas Sieverding
@Bajix
Dec 12 2016 21:21
Yea, so then that test would pass in 2.3 and fail in 3.0
Justin Meyer
@justinbmeyer
Dec 12 2016 21:21
oh
the 2nd part
well, DefineMap didn't exist in 2.3
Thomas Sieverding
@Bajix
Dec 12 2016 21:22
Sure, but comparing can.Map.prototype.attr to DefineMap.prototoype.get
Justin Meyer
@justinbmeyer
Dec 12 2016 21:22
yes ... so we need to know ... what is the behavior of Map (in either 3.0 or 2.3) and compare that to DefineMap
Thomas Sieverding
@Bajix
Dec 12 2016 21:25
Yea, just confirmed. In 2.3 attr() uses all enumerable props
Justin Meyer
@justinbmeyer
Dec 12 2016 21:26
I'm not sure what you mean by "enumerable"
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:27
@Bajix can you make a jsbin ?
Justin Meyer
@justinbmeyer
Dec 12 2016 21:27
there's no concept of "enumerability" in 2.3 ... there's just props in this._data
the closest thing is just serialize: false or serialize: true
Thomas Sieverding
@Bajix
Dec 12 2016 21:28
Well, I guess a for in loop maybe wouldn’t apply in 2.3
2.3 .attr uses all props that don’t use getters
So it’s basically just a copy of this._data
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:30
ah hmmm you i think i understand i do that via a custom getter that simply returns this.foo, this.bar
in can 3
Thomas Sieverding
@Bajix
Dec 12 2016 21:31
The use case I had for this was to use .attr to make backups that included props that wouldn’t serialize
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:32
backups woot?
why should you backup that ?
Thomas Sieverding
@Bajix
Dec 12 2016 21:32
Then I combined that with jdiff to emit patch events whenever I got a patch from my API, as well as hooked into updateInstance
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:33
sounds like your application was broken and you did a hotfix
:D
Thomas Sieverding
@Bajix
Dec 12 2016 21:33
Well something like updatedAt I wouldn’t want to serialize with my save requests, but I would receive from all my responses
Justin Meyer
@justinbmeyer
Dec 12 2016 21:33
so lets use the term "virtual" properties
Map.prototype.attr ... does or does not return "virtual" properties?
Thomas Sieverding
@Bajix
Dec 12 2016 21:34
Well, it’s not virtual - these are properties that are in the database
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:34
@Bajix canjs has nothing to do with a database
Justin Meyer
@justinbmeyer
Dec 12 2016 21:34
"virtual properties" === use a defined getter
lets use that definition for now
Thomas Sieverding
@Bajix
Dec 12 2016 21:34
Sure
Justin Meyer
@justinbmeyer
Dec 12 2016 21:35
Map.prototype.attr ... does or does not return "virtual" properties?
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:35
and real propertys are strings or what?
Thomas Sieverding
@Bajix
Dec 12 2016 21:35
Map.prototype.attr returns virtual props
Justin Meyer
@justinbmeyer
Dec 12 2016 21:35
DefineMap.prototype.get ... does or does not return "virtual" properties?
Thomas Sieverding
@Bajix
Dec 12 2016 21:35
Doesn't
Justin Meyer
@justinbmeyer
Dec 12 2016 21:35
there we go :-)
sorry .. had to get this into some language I understand
going to update the issue with this real quick
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:36
maybe write a vocabulary book or some wiki
english to justin and justin to english
:D
Thomas Sieverding
@Bajix
Dec 12 2016 21:36
Fair, but I still think virtual isn’t the right way to describe this, as I also have actual virtual props on my models
Justin Meyer
@justinbmeyer
Dec 12 2016 21:37
perhaps not
I do think enumerable WILL be the right way
but it's not a "concept" in DefineMap right now
Thomas Sieverding
@Bajix
Dec 12 2016 21:38
Can DefineMap do for in?
Justin Meyer
@justinbmeyer
Dec 12 2016 21:39
unfortunately not the way it would really need to ...
in short ... defineMap is really mutating the prototype
so for/in on instances that would use hasOwnProperty wouldn't actually work
Thomas Sieverding
@Bajix
Dec 12 2016 21:41
What if we changed the enumerable flag on internal properties such that Object.keys / for in will work our of the box?
Justin Meyer
@justinbmeyer
Dec 12 2016 21:41
I looked into this and couldn't find a way to do it
I might have missed something ... but JS doesn't seem to have the right symbols to allow access to these things
Thomas Sieverding
@Bajix
Dec 12 2016 21:42
We could maybe even make it such that Object.keys observes __keys
What prevents it?
Justin Meyer
@justinbmeyer
Dec 12 2016 21:42
there's no symbol to allow it
I think for/of has a symbol
but not for/in
"Symbols are not enumerable in for...in iterations"
That’s the issue?
so it looks like can.Map DOES NOT include virtual properties
var Person = can.Map.extend({
  define: {
    fullName: {
      get: function(){
        return this.first + " " + this.last;
      }
    }
  }
});


var me = new Person({
  first: "Justin",
  last: "Meyer"
})

console.log( me.attr() )
Thomas Sieverding
@Bajix
Dec 12 2016 21:44
It doesn’t include getters, but anything set on ._data
Justin Meyer
@justinbmeyer
Dec 12 2016 21:45
yeah, I guess I'm still trying to find the difference
which you are seeing
do you mean properties defined after initialization?
Thomas Sieverding
@Bajix
Dec 12 2016 21:46
var Person = can.Map.extend({
  define: {
    fullName: {
      get: function(){
        return this.first + " " + this.last;
      }
    },
    updatedAt: {
      type: 'date',
      serialize: false
    }
  }
});


var me = new Person({
  first: "Justin",
  last: "Meyer",
  updatedAt: new Date()
})

console.log( me.attr() )
So that would have first last and updatedAt
But serialize would just be first & last
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:47
so exclude all pros that have .get?
Thomas Sieverding
@Bajix
Dec 12 2016 21:47
So specifically properties that have serialize: false and don’t use get
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:48
exactly thats what i am doing via a custom prob.get function
:D
in can3
you can iritate over this
Justin Meyer
@justinbmeyer
Dec 12 2016 21:49
gotcha
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:51
@justinbmeyer can this syntax where i created a issu for the ES2015 get namedObject() {' be used with can 2.3 define map also ?'}
when yes would it this.attr() return that values
Justin Meyer
@justinbmeyer
Dec 12 2016 21:51
it can not
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:51
ok
Justin Meyer
@justinbmeyer
Dec 12 2016 21:52
it's not ES2015 btw
it's ES5
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:52
ES5.1
Justin Meyer
@justinbmeyer
Dec 12 2016 21:52
yeah
Frank Lemanschik
@frank-dspeed
Dec 12 2016 21:52
yes
:D
sorry for that i am not so correct most times while chating :)
your a more exact person then me
i am lazy in such things but that leads to the nice thing that i create bugs that can be called random futures
realy magic ;)
Justin Meyer
@justinbmeyer
Dec 12 2016 22:43
@Bajix canjs/can-define#63
read that over and let me know ... if you want to take it on, it shouldn't be too difficult
Thomas Sieverding
@Bajix
Dec 12 2016 23:06
@justinbmeyer Looks spot on. I can take that on, but I’d have higher priorities until Wednesday
Trying to get two projects to 3.x between today and tomorrow
I’ll totally hero that though