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

component does not respect can.compute passed via attributes #540

Closed
wclr opened this issue Nov 12, 2013 · 4 comments
Closed

component does not respect can.compute passed via attributes #540

wclr opened this issue Nov 12, 2013 · 4 comments
Milestone

Comments

@wclr
Copy link
Contributor

wclr commented Nov 12, 2013

In latest master:

<my-component blocks="blocks"></my-component>

if blocks is can.compute of parent scope it is not passed to component's scope.

It is because of component.js code (line 105)

var computeData = hookupOptions.scope.computeData(value, {args: []}),
     compute = computeData.compute;
...
initalScopeData[name] = compute();

compute() returns undefined

It worked in previous versions.

justinbmeyer added a commit that referenced this issue Nov 14, 2013
@wclr
Copy link
Contributor Author

wclr commented Nov 17, 2013

Justin, well, actually I hoped that compute would be be passed as a compute function not as value here is a modified test for this:

test("component does not respect can.compute passed via attributes (#540)", function(){

    var data = {
        compute: can.compute(30)
    }

    can.Component.extend({
        tag: "my-component",
        template: "<span>{{blocks}}</span>",

        scope: {
            init: function(){
                // currently this.blocks is just a value of 30
                this.blocks(45)
            }
        }


    })

    var template = can.view.mustache("<my-component blocks='compute'></my-component>");

    var frag  = template(data)

    equal(frag.childNodes[0].childNodes[0].innerHTML, "45")

});

@justinbmeyer
Copy link
Contributor

Yes, but you should still be able to do this.attr('blocks', 45 ). This keeps a component's internal API consistent no matter what you pass it.

@wclr
Copy link
Contributor Author

wclr commented Nov 17, 2013

Ok, that makes sense.

@wclr
Copy link
Contributor Author

wclr commented Nov 18, 2013

Don't you think that if component's attr is changed this.attr('blocks', 45 ), then data.compute() value should be updated to? Not it is not, stays the same.

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

No branches or pull requests

2 participants