Skip to content

Commit

Permalink
Merge pull request #426 from meteor/fix-observe-sequence-dotvalues
Browse files Browse the repository at this point in the history
Fix observe-squence has-implementation, close to underscore
  • Loading branch information
Grubba27 authored Dec 29, 2023
2 parents fdf9296 + ed24e5a commit dac3adf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions packages/observe-sequence/observe_sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
8 changes: 4 additions & 4 deletions packages/observe-sequence/observe_sequence_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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]}
]);
});

Expand Down

0 comments on commit dac3adf

Please sign in to comment.