Closed CaptainN closed 8 months ago
This is a tough one, even if we disregard backward compatibility. I would be more for the second approach as it at least reduces import statements and makes it clear that the collection has been enhanced.
@StorytellerCZ @CaptainN I have a proposal implemented but I can't open the PR (it always fails from GitHub's side). The branch is lazy-export. The PR is #430
The idea is to once load the module actively before the first attachSchema
is called:
import Collection2 from 'meteor/aldeed:collection2'
Collection2.load()
I believe my solution would have achieved the same thing. For code splitting, you'd need to import that everywhere that might be "split" - so before every collection creation.
Honestly, I'm moving away from Collection2, so I no longer have a strong opinion about this.
Support the lazy flag, for better code splitting (dynamic-import). This is a breaking change, so it'd require a version bump, but it would also allow us to avoid packing the large dependencies (Mongo/MiniMongo, SimplSchema) in the initial bundle. These changes saved me about 200kb in my initial bundle.
I can make a PR, but there are things to discuss. Doing this would mean the package needs to be imported somewhere before
MyCollection.attachSchema
is invoked. I have done it this way:But maybe it would be better if we exported Mongo or even Collection directly from the Collection2 package?