From 38a87581c6b042ce2bf15045585f0e52a34cc469 Mon Sep 17 00:00:00 2001 From: jankapunkt Date: Sat, 5 Aug 2023 09:15:48 +0200 Subject: [PATCH 1/2] fix(observer-squence): use has-implementation, close to underscore --- packages/observe-sequence/observe_sequence.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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 () { From ed24e5ac3d558feaf967d4c7a29de4d5273dc7d0 Mon Sep 17 00:00:00 2001 From: jankapunkt Date: Mon, 4 Dec 2023 15:46:50 +0100 Subject: [PATCH 2/2] tests: added testing _ids with dotvalues --- packages/observe-sequence/observe_sequence_tests.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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]} ]); });