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.route triggers event two times for setting nested object. #269

Closed
schovi opened this issue Feb 7, 2013 · 8 comments
Closed

can.route triggers event two times for setting nested object. #269

schovi opened this issue Feb 7, 2013 · 8 comments
Assignees
Milestone

Comments

@schovi
Copy link
Contributor

schovi commented Feb 7, 2013

I want to use two level object in route for control some panel with widgets.
When i want to make widget visible i can easily trigger
can.route.attr({notifications: {messages: true}})
and when i want to hide it i will call
can.route.removeAttr('notifications.messages')
and each widget listen on route change for given 'code'
can.route.bind('notifications.messages', function() {....})
Idea worked fine until i find some strange behaviour that event is triggered 2 times.
First for whole object {notifications ...}
Second for notifications.messages (And there it pass new value as stringified "true" and old value as standard true

Thing with stringified true is even more stranger :)

More in console in this Fiddle

@daffl
Copy link
Contributor

daffl commented Feb 8, 2013

Does your pull request #272 solve this?

@schovi
Copy link
Contributor Author

schovi commented Feb 8, 2013

No, it is different problem.

@schovi
Copy link
Contributor Author

schovi commented Mar 18, 2013

Maybe similar to this one #280

@justinbmeyer
Copy link
Contributor

Part of the issue is:

can.route.attr({notifications: {messages: true}})

You are passing a non-string value, but this gets added to the hash, which converts it to a string, hence the double change.

We could try to force every incoming value to a string in can.route.

Can you create a test?

@justinbmeyer
Copy link
Contributor

I think you can fix this with the define plugin:

var RouteState = can.Map.extend({
  define: {
    messages: {
       type: "boolean"
    }
  }
})

can.route.map(new RouteState);
can.route.ready()

can.route.bind("messages", function(){})

can.route.attr("messages", true);
can.route.attr("messages", false);

@daffl
Copy link
Contributor

daffl commented Feb 11, 2015

I would double check if this hasn't been fixed with #1187 yet which I merged yesterday.

@daffl
Copy link
Contributor

daffl commented Feb 11, 2015

Nervemind, that looks like it's something different.

@daffl daffl added this to the 2.3.0 milestone Feb 12, 2015
@JaneOri
Copy link

JaneOri commented Sep 17, 2015

Looks to be fixed.
http://jsbin.com/remujuziho/edit?html,js,output

test( "deep param bind doesn't fire twice on remove", function () {
  expect( 1 );
  can.route.bind( "prop.deep", function () {
    ok( true, "only fired once because prop.deep changes" );
  });
  can.route.attr( { prop: { deep: true } } );
  // issue #269, remove would fire the change event for "prop.deep" AND "prop"
  can.route.removeAttr( "prop.deep" );
});

@JaneOri JaneOri closed this as completed Sep 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants