diff --git a/packages/observe-sequence/observe_sequence.js b/packages/observe-sequence/observe_sequence.js index fd4a591c3..b0fc256c6 100644 --- a/packages/observe-sequence/observe_sequence.js +++ b/packages/observe-sequence/observe_sequence.js @@ -2,14 +2,16 @@ const isObject = function (value) { var type = typeof value; return value != null && (type == 'object' || type == 'function'); } -const has = function (obj, key) { - var keyParts = key.split('.'); - - return !!obj && ( - keyParts.length > 1 - ? has(obj[key.split('.')[0]], keyParts.slice(1).join('.')) - : hasOwnProperty.call(obj, key) - ); +const has = (obj, path) => { + const thisPath = Array.isArray(path) ? path : [path]; + const length = thisPath.length; + for (let i = 0; i < length; i++) { + const key = thisPath[i]; + const _has = obj != null && Object.hasOwnProperty.call(obj, key); + if (!_has) return false; + obj = obj[key]; + } + return !!length; }; const warn = function () { diff --git a/packages/observe-sequence/observe_sequence_tests.js b/packages/observe-sequence/observe_sequence_tests.js index 7f62a0f47..a0e91dc58 100644 --- a/packages/observe-sequence/observe_sequence_tests.js +++ b/packages/observe-sequence/observe_sequence_tests.js @@ -476,7 +476,7 @@ Tinytest.add('observe-sequence - cursor to null', function (test) { Tinytest.add('observe-sequence - cursor to array', function (test) { var dep = new Tracker.Dependency; var coll = new Mongo.Collection(null); - coll.insert({_id: "13", foo: 1}); + coll.insert({_id: "13.5", foo: 1}); var cursor = coll.find({}, {sort: {_id: 1}}); var seq = cursor; @@ -485,14 +485,14 @@ Tinytest.add('observe-sequence - cursor to array', function (test) { return seq; }, function () { coll.insert({_id: "37", bar: 2}); - seq = [{_id: "13", foo: 1}, {_id: "38", bar: 2}]; + seq = [{_id: "13.5", foo: 1}, {_id: "38", bar: 2}]; dep.changed(); }, [ - {addedAt: ["13", {_id: "13", foo: 1}, 0, null]}, + {addedAt: ["13.5", {_id: "13.5", foo: 1}, 0, null]}, {addedAt: ["37", {_id: "37", bar: 2}, 1, null]}, {removedAt: ["37", {_id: "37", bar: 2}, 1]}, {addedAt: ["38", {_id: "38", bar: 2}, 1, null]}, - {changedAt: ["13", {_id: "13", foo: 1}, {_id: "13", foo: 1}, 0]} + {changedAt: ["13.5", {_id: "13.5", foo: 1}, {_id: "13.5", foo: 1}, 0]} ]); });