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.computes with can.Map.prototype.attr() do not set up bindings #626

Merged
merged 2 commits into from Jan 7, 2014

Conversation

Projects
None yet
3 participants
@onyxrev
Contributor

onyxrev commented Dec 21, 2013

If I use can.Map.prototype.attr() in a can.compute it doesn't set up a binding like can.Map.prototype.attr("some_property") does. I often use computes to generate dynamic links and I use .attr() to serialize the data in a can.Map for use in creating the URL parameters, for example. You may not know what data will be inside the can.Map, for example, so might want to use .attr() to explode the values out when they change.

Doesn't work:

var listenToMe = new can.Map({ iChange: "fromThis" });

can.compute(function(){
    return listenToMe.attr().iChange;
});

listenToMe.attr("iChange", "toThis");

Does work:

var listenToMe = new can.Map({ iChange: "fromThis" });

can.compute(function(){
    return listenToMe.attr("iChange");
});

listenToMe.attr("iChange", "toThis");

Example of dynamic URL:

can.compute(function(){
    var routeParams = $.extend({}, listenToMe.attr(), { analytics_section_code: "report_builder", report: reportCode });
    return can.route.url(routeParams);
});
@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 21, 2013

Contributor

I actually noticed that today while reviewing can.Map's source code. _attrs doesn't call .attr() which calls can.__reading to signal live-binding.

Contributor

justinbmeyer commented Dec 21, 2013

I actually noticed that today while reviewing can.Map's source code. _attrs doesn't call .attr() which calls can.__reading to signal live-binding.

onyxrev added a commit to onyxrev/canjs that referenced this pull request Dec 21, 2013

@onyxrev

This comment has been minimized.

Show comment
Hide comment
@onyxrev

onyxrev Dec 21, 2013

Contributor

Maybe a naive fix? I haven't been in this part of the code before but this definitely works.

Contributor

onyxrev commented Dec 21, 2013

Maybe a naive fix? I haven't been in this part of the code before but this definitely works.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 21, 2013

Contributor

Thanks. Anyway you could add a test? Also, can you add a check that it updates if you add a property too? You will need to tell __reading about the __keys event (you can find this happening other places).

Ah, too bad you missed the hangout today where I went over can.Map in detail :-).

Contributor

justinbmeyer commented Dec 21, 2013

Thanks. Anyway you could add a test? Also, can you add a check that it updates if you add a property too? You will need to tell __reading about the __keys event (you can find this happening other places).

Ah, too bad you missed the hangout today where I went over can.Map in detail :-).

@onyxrev

This comment has been minimized.

Show comment
Hide comment
@onyxrev

onyxrev Dec 21, 2013

Contributor

Okay - will do.

Contributor

onyxrev commented Dec 21, 2013

Okay - will do.

onyxrev added a commit to onyxrev/canjs that referenced this pull request Dec 21, 2013

onyxrev added a commit to onyxrev/canjs that referenced this pull request Dec 21, 2013

@onyxrev

This comment has been minimized.

Show comment
Hide comment
@onyxrev

onyxrev Dec 21, 2013

Contributor

It works on addition and subtraction of properties. Added __keys and test.

Contributor

onyxrev commented Dec 21, 2013

It works on addition and subtraction of properties. Added __keys and test.

onyxrev added a commit to onyxrev/canjs that referenced this pull request Dec 21, 2013

onyxrev added a commit to onyxrev/canjs that referenced this pull request Dec 21, 2013

onyxrev added a commit to onyxrev/canjs that referenced this pull request Dec 21, 2013

daffl added a commit that referenced this pull request Jan 7, 2014

Merge pull request #626 from onyxrev/onyxrev/map_attr_reading_fix
can.computes with can.Map.prototype.attr() do not set up bindings

@daffl daffl merged commit a81c1d7 into canjs:master Jan 7, 2014

1 check passed

default The Travis CI build passed
Details
@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Jan 7, 2014

Contributor

@onyxrev Thanks big time for the fix!

Contributor

justinbmeyer commented Jan 7, 2014

@onyxrev Thanks big time for the fix!

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Feb 3, 2014

Contributor

IE7 doesn't support indexOf ... I'll update this to work.

Contributor

justinbmeyer commented on map/map_test.js in 02a797a Feb 3, 2014

IE7 doesn't support indexOf ... I'll update this to work.

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Feb 3, 2014

Contributor

using can.inArray instead

Contributor

justinbmeyer replied Feb 3, 2014

using can.inArray instead

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