-
Notifications
You must be signed in to change notification settings - Fork 422
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
Allow to assign object as attribute type (in can.Observe) #107
Comments
How does it know to call new Items or simply Items? I don't know if this will work. |
You can pass attributes functions. That will work. |
why call just Items, in what case does it make sense? at list if Items is Construct/Observer or Observe.List/Model.List it does make sense to all new Items, no? |
attributes:{ Sent from my iPhone On Sep 17, 2012, at 10:29 AM, Alex Osh notifications@github.com wrote:
|
Yes, using function is good, but why not make it automatically. |
There's no great way to tell a function that is intended to be called with new vs a normal function. In js a constructor function is just a function. It's how you call it that matters. Sent from my iPhone On Sep 17, 2012, at 11:13 AM, Alex Osh notifications@github.com wrote:
|
Because it's very common to not pass a constructor and a function that might pick between various constructors. Or pass something like Date.parse. Sent from my iPhone On Sep 17, 2012, at 11:19 AM, Alex Osh notifications@github.com wrote:
|
Ok, it's just proposal. You know better. But for standard objects like Costruct/Observer/Model/List probably it could be done. |
I was more thinking along the line of the object providing its own conversion and serialization methods so that you don't have to implement an additional wrapper: return can.Construct({
convert : function() {
},
serialize : function() {
}
}, {});
steal('can/observe/attributes', 'items.js', function(Observe, Items){
return Observe({
attributes: {
items: Items // Items is object not 'Items' string
}
}); I think #106 is related to that as well (automatic conversion in Observe.List subclasses). |
Yes they (107 and 106) relates. What I propose that if you wnat to get Observe.List named for example Blocks = Block.List (which assumed to be collection of elements of type Block), instead of code: attributes: {
items: function(items){
return new Blocks(items.map(function(item){
return new Block(item)
}))
}
} It would be much more elegant to write just like that: attributes: {
items: Blocks
} |
Hm, GitHub wasn't supposed to close the issue from a branch. Anyway, @whitecolor check out this branch. The attributes plugin lets you do things like this now:
|
Currently one can assign model/list name (string) as attribute type for automatic conversion. But if there is no such object in window context (for an example AMD case) it is impossible to do so.
I would propose to use model/list objects it self for declaring attribute type.
then observe knows what type to convert to.
The text was updated successfully, but these errors were encountered: