These are chat archives for canjs/canjs

3rd
Nov 2016
Eben
@eben-roux
Nov 03 2016 13:56
mope.io
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:25
Eben
is this your project?
Gregg Roemhildt
@roemhildtg
Nov 03 2016 14:49
Good day, quick question on canjs 3. (I know I have a lot of questions) In the previous version, can.Map.define objects could have a set function which would be called when the property is initialized (like with a default value) or set. But does this still happen in version 3? http://jsbin.com/kepixenonu/edit?html,js,console,output
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:50
maybe you should watch the fresh new stylish guids and page for it? :D
go on the left side to infrastructure ecosystem and all that
and you will have a much better understanding and overview about the options and whats used
if you have any questions that this don't solves plz tell it here so some one can write something about that
Kevin Phillips
@phillipskevin
Nov 03 2016 14:53
@roemhildtg can-map-define is the same as what you’re talking about from 2.3
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:54
@phillipskevin but the name changed a bit var DefineMap = require("can-define/map/map");
Kevin Phillips
@phillipskevin
Nov 03 2016 14:54
no
can-map-define is the same
can-define/map/map is a slightly different thing
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:54
ah now we are on the same point :)
Gregg Roemhildt
@roemhildtg
Nov 03 2016 14:54
Oh, I see.
Kevin Phillips
@phillipskevin
Nov 03 2016 14:54
can-map/can-map-define has attr() and works the same as the Map and define plugin in 2.3
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:55
DifineMap nativ should get depricated or not?
Kevin Phillips
@phillipskevin
Nov 03 2016 14:55
DefineMap you don’t need to use attr()
Gregg Roemhildt
@roemhildtg
Nov 03 2016 14:55
I like using DefineMap since there's no need for attr
Kevin Phillips
@phillipskevin
Nov 03 2016 14:55
DefineMap is the new way
Gregg Roemhildt
@roemhildtg
Nov 03 2016 14:55
But can you confirm whether or not the set behavior has changed?
Kevin Phillips
@phillipskevin
Nov 03 2016 14:55
set works the same
it’s the value that is not working in your example I think
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:56
the old works but should complain when using attr
Kevin Phillips
@phillipskevin
Nov 03 2016 14:56
no can-map-define is a different module
you have to use attr
@roemhildtg
let a = can.DefineMap.extend('a', {
  init(){
    console.log(arguments);
  },
  val: {
    set(val){
      console.log('hey there', val);
      return val;
    }
  }
})
let b = new a();
b.val = 'Hello';
console.log(b.val)
that does what you’re expecting
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:57
ya but you agre with me that we don't use that this way any more as we do var DefineMap = require("can-define/map/map");
Kevin Phillips
@phillipskevin
Nov 03 2016 14:57
don’t use what this way?
can-map and can-map-define are legacy modules
for backward compatibility
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:57
we don't use can-map-define in donejs examples
ya
thats what i mean they are still updated but not used any more
Kevin Phillips
@phillipskevin
Nov 03 2016 14:58
the donejs examples will be updated to use DefineMap, yeah
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:58
they get replaced by the lazy models
Kevin Phillips
@phillipskevin
Nov 03 2016 14:58
and generators, etc
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:58
ya thats what i mean :)
Gregg Roemhildt
@roemhildtg
Nov 03 2016 14:58
Okay, but I can provide a default value still, its just this doesn't call the set method anymore?
Frank Lemanschik
@frank-dspeed
Nov 03 2016 14:58
i depricated it and throw it out all over
Oh @phillipskevin do you maybe know or tryed it what happens to a 2.3 project when you switch do can3.0
and use the legacy stuff does it work?
Kevin Phillips
@phillipskevin
Nov 03 2016 15:00
yes
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:00
so we are compatible wow
Kevin Phillips
@phillipskevin
Nov 03 2016 15:00
yeah, we have client projects that are upgrading to 3.0
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:00
don't knowed that fact should consider that in the genrator
ya upgrading means for me also changing the components
i mean it works to only change the requires and imports and they still work nothing left out?
Kevin Phillips
@phillipskevin
Nov 03 2016 15:01
no, you do have to make some changes
@roemhildtg to answer your question… I’m not sure
Gregg Roemhildt
@roemhildtg
Nov 03 2016 15:03
I've been doing the future proof migration, its not so bad. It cleans up the code a lot removing all of the .attr stuff
Kevin Phillips
@phillipskevin
Nov 03 2016 15:04
I don’t think setting a default value on DefineMap like that does what you want
Gregg Roemhildt
@roemhildtg
Nov 03 2016 15:10
Okay just thought I'd ask. I do know that in the previous version set would be called when the default value was set. http://jsbin.com/wicuguwisa/edit?html,js,console,output
Kevin Phillips
@phillipskevin
Nov 03 2016 15:10
yeah
there are some differences with the order of how the define properties get set up
if that’s something you need, feel free to open an issue
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:12
@phillipskevin do you have a idea what happens to such?
Kevin Phillips
@phillipskevin
Nov 03 2016 15:13
not sure what you mean
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:13

canMap.extend(
/ @prototype */
{
define: {
/

     * @property {office/models/session} office/components/navigation.loginSession loginSession
     * @parent office/components/navigation.properties
     *
     * A placeholder session with a nested [office/models/user user] property that
     * is used for two-way binding the login form's username and password.
     */
    loginSession: {
        value: function(){
            return new Session({user: new User()});
        }
    }
    /**
     * @property {office/app} office/components/navigation.app app
     * @parent office/components/navigation.properties
     *
     * The [office/app] used to add or destroy the session.
     */
     /**
      * @property {Promise<office/models/session>} office/components/navigation.sessionPromise sessionPromise
      * @parent office/components/navigation.properties
      *
      * The promise that resolves when the user is logged in.
      */
},
/**
 * @function createSession
 *
 * Creates the session on the server and when successful updates [office/components/navigation.app]
 * with the session. Sets [office/components/navigation.sessionPromise].
 * @param {Event} [ev] Optional DOM event that will be prevented if passed.
 */
createSession: function(ev){
    if(ev) {
        ev.preventDefault();
    }
    var self = this;
    var sessionPromise = this.attr("loginSession").save().then(function(session){

        self.attr("loginSession", new Session({user: new User()}));
        self.attr("app").attr("session", session);

    });
    this.attr("sessionPromise", sessionPromise);
},

```

you see we have a map and then define:{}
and functions under the define
Gregg Roemhildt
@roemhildtg
Nov 03 2016 15:14
Okay, good to know. I think its useful. I'll put in an issue.
Kevin Phillips
@phillipskevin
Nov 03 2016 15:14
@frank-dspeed yeah… that’s how can-map and can-map-define work
you can have a CanMap without the define plugin
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:14
i mean
var DefineMap = require("can-define/map/map");
in this case it should only set the define: {} part
not the functions after it right?
whats the component for the functions in can map after the define
Kevin Phillips
@phillipskevin
Nov 03 2016 15:15
you can put functions on a DefineMap
those functions can be called from other properties on the map or from the template
inside the define: {}, the define plugin will take the set, get, etc properties and create a compute on the Map instance
outside the define, those things will just be set on the Map instance directly
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:19
ah
so we have magic that exports it from define to parent map
good to know
Kevin Phillips
@phillipskevin
Nov 03 2016 15:20
yeah
that’s what can-map-define does
Frank Lemanschik
@frank-dspeed
Nov 03 2016 15:21
it defines a map :)
sounds logical
i am so lost in the nodejs parts of the project at present that i lost totally the view for the web component evolution :)