Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
658 stars 90 forks source link

Specify which fields of a document to pull into the before/after update hooks #256

Closed znewsham closed 1 year ago

znewsham commented 4 years ago

This PR makes two changes:

  1. A bug fix: If you define any after hooks, the before hook will fetch the previous document, even if fetchPrevious is set to false.
  2. A new feature allowing you to specify which fields of a document should be pulled in if fetchPrevious is true

for (2) you can either specify the fields as globals or on a specific aspect as follows:

  Collection.hookOptions.after.update = { fetchFields: { _id: 1, field1: 1, field2: 1, field3: 1 } };

By default you get all fields (so the default behaviour has not changed)

The tests all pass, however another set of eyes would be useful!

StorytellerCZ commented 4 years ago

@znewsham Hello and thank you for your contribution! I have merged modernization PR so there will be some conflicts, but those should be easy to resolve.

copleykj commented 4 years ago

I've manually fixed the conflicts for this, but we now have failing tests due to the absence of jQuery in 1.8.3. Is there a way to configure which npm packages are installed before tests are run?

sebakerckhof commented 4 years ago

Yes, you can use the --test-app-path ./path/to/test-app argument to a directory containing a package.json file. Here's an example how we did it for blaze https://github.com/meteor/blaze/commit/f13c2ad979fb56cd3160f105eb5b9a7d61b8ef43

copleykj commented 4 years ago

Awesome, thanks @sebakerckhof

copleykj commented 4 years ago

@StorytellerCZ could you take a look at the failing tests and see if you can get them to pass? I've not been able to manage it.

StorytellerCZ commented 4 years ago

@copleykj I'll see if I can get some time on this over the weekend.

StorytellerCZ commented 4 years ago

@copleykj Looks like an issue with spacejam, when running tiny test on its own the test pass.