Skip to content

Children don't bubble parent with functions #146

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

Merged
merged 3 commits into from
Sep 16, 2019

Conversation

cherifGsoul
Copy link
Member

@cherifGsoul cherifGsoul commented Sep 11, 2019

This is needed to fix canjs/can-list#97

The issue

An error is thrown when function events is bubbled to parent, the check is made by .bind

if (child && child.bind) {

for that reason, functions are always bubbled.

The changes

  • Update childrenOf in bubble.js to bubble events to parent only on Objects/Map
  • Make a test file for bubble.js

bubble.js Outdated
@@ -144,7 +144,9 @@ var bubble = {
// For an event binding on an object, returns the events that should be bubbled.
// For example, `"change" -> ["change"]`.
events: function(map, boundEventName) {
return map.constructor._bubbleRule(boundEventName, map);
if (map && typeof map === 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When should bubbling happen? I think there is probably a better way to do this check. Either using canReflect.isFunctionLike or canReflect.isMapLike.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should check !canReflect.isFunctionLike(map) and the one in childrenOf should use canReflect.isMapLike(child)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phillipskevin I made the requested updates.

canReflect.isMapLike(child) returns true with a function, so I just used !canReflect.isFunctionLike for both .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does the .childrenOf need && child.bind? What is this check for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is the old way to check if the object is a can-map!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this is what I meant to use isMapLike for

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

@cherifGsoul cherifGsoul merged commit 70fb037 into master Sep 16, 2019
@cherifGsoul cherifGsoul deleted the no-function-children-parent-bubbling branch September 16, 2019 18:06
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

Successfully merging this pull request may close these issues.

"Unable to bind change" when having CanList items with function properties
2 participants