broccolijs / broccoli-persistent-filter

MIT License
12 stars 33 forks source link

Initialize processor in `build`, prevent reusing same strategy #218

Closed brendenpalmer closed 1 year ago

brendenpalmer commented 1 year ago

Currently in broccoli-persistent-filter, it's not really possible to use your own state on your subclass of it in the overall bucket cacheKey for a few reasons:

  1. It initializes the persistent strategy on the constructor as part of the super call, then immediately stashes a memoized cache key on the constructor; this makes it difficult to instrument cacheKey with state that you have on your subclass without workarounds.
  2. The persistent strategy object is reused by reference, which causes new instances of broccoli-persistent-filter to clobber properties (namely the caches) on the persistent strategy object.

This PR resolves both of these issues. We now only initialize the processor in build, but we guard it to only do this once; we also shallow clone the strategy object, so we don't unnecessarily reuse it across instances of broccoli-persistent-filter.