Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix observe-squence has-implementation, close to underscore #426

Merged
merged 5 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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