Skip to content
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

can.List compute properties #790

Closed
moschel opened this issue Mar 14, 2014 · 2 comments
Closed

can.List compute properties #790

moschel opened this issue Mar 14, 2014 · 2 comments
Labels

Comments

@moschel
Copy link
Contributor

moschel commented Mar 14, 2014

It seems there is an inconsistency in how can.Map properties and can.List properties can be defined as computes. After defining a compute in can.Map, it can be referenced with obj.attr('computePropName'), but for can.List instances, list.attr('computePropName') returns a function, not the result of the compute.

Person = can.Map.extend({
    speak: can.compute(function(){
        return "foo"
    })
})
var p = new Person();
console.log('map speak', p.attr('speak'))

People = can.List.extend({
    speak: can.compute(function(){
        return "foo"
    })
})
var list = new People([1, 2, 3]);
console.log('map speak', list.attr('speak'));

outputs the following:

map speak foo 
map speak function (c){if(arguments.length){var b=q,e=w.call(d,c,b);if(m.hasDependencies)return r.call(d);q=void 0===e?r.call(d):e;b!==q&&a.batch.trigger(m,
"change",[q,b]);return q}a.__reading&&y&&(a.__reading(m,"change"),p.bound||a.compute.temporarilyBind(m));return p.bound?q:r.call(d)} 
@moschel moschel added the Bug label Mar 14, 2014
@justinbmeyer
Copy link
Contributor

I think this is a duplicate issue.

Sent from my iPhone

On Mar 14, 2014, at 1:18 AM, Brian Moschel notifications@github.com wrote:

It seems there is an inconsistency in how can.Map properties and can.List properties can be defined as computes. After defining a compute in can.Map, it can be referenced with obj.attr('computePropName'), but for can.List instances, list.attr('computePropName') returns a function, not the result of the compute.

Person = can.Map.extend({
speak: can.compute(function(){
return "foo"
})
})
var p = new Person();
console.log('map speak', p.attr('speak'))

People = can.List.extend({
speak: can.compute(function(){
return "foo"
})
})
var list = new People([1, 2, 3]);
console.log('map speak', list.attr('speak'));
outputs the following:

map speak foo
map speak function (c){if(arguments.length){var b=q,e=w.call(d,c,b);if(m.hasDependencies)return r.call(d);q=void 0===e?r.call(d):e;b!==q&&a.batch.trigger(m,
"change",[q,b]);return q}a.__reading&&y&&(a.__reading(m,"change"),p.bound||a.compute.temporarilyBind(m));return p.bound?q:r.call(d)}

Reply to this email directly or view it on GitHub.

@isadovskiy
Copy link

I'm interesting in the answer too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants