New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes automatic conversion to Map/Model specified type #293

Merged
merged 2 commits into from Oct 11, 2013

Conversation

Projects
None yet
3 participants
@daffl
Contributor

daffl commented Oct 11, 2013

Please add this feature:

if Item is can.Observe

attributes: {
   items: Item.List
}

Items would be automatically converted to Item.List without need of using "convert"

@Wizardum

This comment has been minimized.

Show comment
Hide comment
@Wizardum

Wizardum Feb 27, 2013

Check this, scroll down to the Associations section.

I think this does what you are asking for. :)

Wizardum commented Feb 27, 2013

Check this, scroll down to the Associations section.

I think this does what you are asking for. :)

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Feb 27, 2013

Contributor

@Wizardum it works only with strings and window object namespace.

Contributor

whitecolor commented Feb 27, 2013

@Wizardum it works only with strings and window object namespace.

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Feb 27, 2013

Contributor

I have that functionality in the issue_107 branch. Here is the attributes plugin documentation. It also entails some other major observe changes though which is why it didn't get merged yet. I'd really like to see that in 1.2 though.

Contributor

daffl commented Feb 27, 2013

I have that functionality in the issue_107 branch. Here is the attributes plugin documentation. It also entails some other major observe changes though which is why it didn't get merged yet. I'd really like to see that in 1.2 though.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Feb 28, 2013

Contributor

So, I believe we have to wait until that a little while )

Contributor

whitecolor commented Feb 28, 2013

So, I believe we have to wait until that a little while )

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Feb 28, 2013

Contributor

If you look at the roadmap you can see that it is planned for around the middle of May. We can't put something it into a patch version like 1.1.5 because it changes the API (even though it will probably be mostly backwards compatible).

Contributor

daffl commented Feb 28, 2013

If you look at the roadmap you can see that it is planned for around the middle of May. We can't put something it into a patch version like 1.1.5 because it changes the API (even though it will probably be mostly backwards compatible).

@ghost ghost assigned daffl Mar 4, 2013

@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Oct 11, 2013

Contributor

I attached a pull request to this issue that will allow conversion like this (also for Maps/Observes):

var Sword = can.Model.extend({
  findAll: 'GET /swords'
}, {
  getPower: function() {
    return this.attr('power') * 100;
  }
});

var Level = can.Model.extend({
  findAll: 'GET /levels'
}, {});

var Zelda = can.Model.extend({
  attributes: {
    sword: Sword,
    levelsCompleted: Level
  }
},{});

var link = Zelda.model({
  sword: {
    name: 'Wooden Sword',
    power: 0.2
  },
  levelsCompleted : [
    {id: 1, name: 'Aquamentus'},
    {id: 2, name: 'Dodongo'}
  ]
};

Instead of Item.List you can just pass Item and if the value is an array it will be automatically converted into a List (either using new Item.List or Item.models it Item is a model).

Contributor

daffl commented Oct 11, 2013

I attached a pull request to this issue that will allow conversion like this (also for Maps/Observes):

var Sword = can.Model.extend({
  findAll: 'GET /swords'
}, {
  getPower: function() {
    return this.attr('power') * 100;
  }
});

var Level = can.Model.extend({
  findAll: 'GET /levels'
}, {});

var Zelda = can.Model.extend({
  attributes: {
    sword: Sword,
    levelsCompleted: Level
  }
},{});

var link = Zelda.model({
  sword: {
    name: 'Wooden Sword',
    power: 0.2
  },
  levelsCompleted : [
    {id: 1, name: 'Aquamentus'},
    {id: 2, name: 'Dodongo'}
  ]
};

Instead of Item.List you can just pass Item and if the value is an array it will be automatically converted into a List (either using new Item.List or Item.models it Item is a model).

daffl added a commit that referenced this pull request Oct 11, 2013

Merge pull request #293 from bitovi/attributes-conversion-293
Attributes automatic conversion to Map/Model specified type

@daffl daffl merged commit 5311d9e into master Oct 11, 2013

1 check passed

default The Travis CI build passed
Details

@daffl daffl deleted the attributes-conversion-293 branch Oct 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment