From 3d28ca714a8abe513b241dab2f5eae4f1f875ada Mon Sep 17 00:00:00 2001 From: Bradley Momberger Date: Tue, 17 Dec 2019 17:36:04 -0500 Subject: [PATCH 1/2] Only set up bubble bindings when children are observable --- bubble.js | 4 ++-- bubble_test.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bubble.js b/bubble.js index d9a5b08..3cffa4d 100644 --- a/bubble.js +++ b/bubble.js @@ -194,11 +194,11 @@ var bubble = { }, // ## bubble.childrenOf - // Bubbles all the children of `parent`. + // Bubbles all the observable children of `parent`. childrenOf: function (parent, eventName) { parent._each(function (child, prop) { - if (isMap(child)) { + if (isMap(child) && canReflect.isObservableLike(child)) { bubble.toParent(child, parent, prop, eventName); } }); diff --git a/bubble_test.js b/bubble_test.js index 6fd1ecb..8a6373d 100644 --- a/bubble_test.js +++ b/bubble_test.js @@ -39,3 +39,14 @@ QUnit.test(".childrenOf should not bubble array", function(assert){ assert.ok(true); }); + +QUnit.test(".childrenOf should not bind nested non-Observables", function(assert){ + + var map = new CanMap({ + type: Object.create({ + label: "hello", + }) + }); + bubble.childrenOf(map, "change"); + assert.ok(true, "Bubble children does not error"); +}); From d08d51793b86ddc6c53fbfbc7e1f3918e4c17280 Mon Sep 17 00:00:00 2001 From: Bradley Momberger Date: Tue, 17 Dec 2019 17:41:53 -0500 Subject: [PATCH 2/2] Refactor bubbling to also handle events reporting --- bubble.js | 11 ++++++++--- bubble_test.js | 5 ++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bubble.js b/bubble.js index 3cffa4d..cffc378 100644 --- a/bubble.js +++ b/bubble.js @@ -28,8 +28,13 @@ var canReflect = require('can-reflect'); // Helper function to check the Map type var isMap = function(map) { - return (map && !canReflect.isFunctionLike(map) && - canReflect.isMapLike(map) && !Array.isArray(map)); + return ( + map && + !canReflect.isFunctionLike(map) && + canReflect.isMapLike(map) && + !Array.isArray(map) && + canReflect.isObservableLike(map) + ); }; @@ -198,7 +203,7 @@ var bubble = { childrenOf: function (parent, eventName) { parent._each(function (child, prop) { - if (isMap(child) && canReflect.isObservableLike(child)) { + if (isMap(child)) { bubble.toParent(child, parent, prop, eventName); } }); diff --git a/bubble_test.js b/bubble_test.js index 8a6373d..103414d 100644 --- a/bubble_test.js +++ b/bubble_test.js @@ -48,5 +48,8 @@ QUnit.test(".childrenOf should not bind nested non-Observables", function(assert }) }); bubble.childrenOf(map, "change"); - assert.ok(true, "Bubble children does not error"); + assert.equal(bubble.events(map.attr("type"), "change"), undefined, "non-Observable child does not bubble"); + map.attr("type", new CanMap({})); + assert.equal(bubble.events(map.attr("type"), "change").length, 1, "replacing with Observable child bubbles"); + });