From ab9b4431ceb05f26b5e1471f4a28dc77cf678b14 Mon Sep 17 00:00:00 2001 From: Justin Meyer Date: Wed, 5 Sep 2018 12:29:29 -0500 Subject: [PATCH] making canReflect.hasOwnKey work --- can-simple-map.js | 7 +++++-- can-simple-map_test.js | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/can-simple-map.js b/can-simple-map.js index 2a0888b..59c31c9 100644 --- a/can-simple-map.js +++ b/can-simple-map.js @@ -60,7 +60,7 @@ var SimpleMap = Construct.extend("SimpleMap", } } //!steal-remove-end - + var dispatched = { keyChanged: !had ? prop : undefined, type: prop @@ -203,7 +203,10 @@ var simpleMapProto = { }, "can.getKeyDependencies": function(key) { return undefined; - } + }, + "can.hasOwnKey": function(key){ + return this._data.hasOwnProperty(key); + } }; //!steal-remove-start diff --git a/can-simple-map_test.js b/can-simple-map_test.js index 65f3513..04b8d1a 100644 --- a/can-simple-map_test.js +++ b/can-simple-map_test.js @@ -242,6 +242,15 @@ QUnit.test("don't dispatch events for sets that don't change", 2, function(){ map.attr("foo","BAR"); }); +QUnit.test("Reflect.hasOwnKey", function(){ + var map = new SimpleMap({a: undefined, b: null, c: ""}); + + QUnit.ok( canReflect.hasOwnKey(map,"a"), "undefined is a key"); + QUnit.ok( canReflect.hasOwnKey(map,"b"), "null is a key"); + QUnit.ok( canReflect.hasOwnKey(map,"c"), "empty string is a key"); + QUnit.ok( !canReflect.hasOwnKey(map,"d"), "no prop is not a key"); +}); + require("can-reflect-tests/observables/map-like/instance/on-get-set-delete-key")("", function(){ return new SimpleMap(); });