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
whitecolor opened this Issue Nov 12, 2013 · 4 comments

Comments

Projects
None yet
2 participants
@whitecolor
Contributor

whitecolor 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

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Nov 17, 2013

Contributor

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")

});
Contributor

whitecolor 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

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Nov 17, 2013

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.

Contributor

justinbmeyer commented Nov 17, 2013

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.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Nov 17, 2013

Contributor

Ok, that makes sense.

Contributor

whitecolor commented Nov 17, 2013

Ok, that makes sense.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Nov 18, 2013

Contributor

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.

Contributor

whitecolor 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