apostrophecms / apostrophecms/apostrophe
Option cloning: as a developer I can instantiate a subclass of a module without inadvertently altering the behavior of the base class and other subclasses
- Dominant language
- JavaScript
- Stars
- 4.6k
- Forks
- 650
- Avg merge
- 19h 21m
- Merged PRs (30d)
- 23
Description
In Apostrophe 2.x, we do not clone module options because moog is used to instantiate cursors too, which happens on every request, and we are concerned about performance.
However in 3.x we only use moog for module inheritance, which happens only at startup. So it is reasonable to consider deep-cloning `options` before assignment.
This would prevent confusing situations where a subclass modifying an option by reference (`self.options.listProjection` receiving a new property, for instance) also affects all other subclasses of `apostrophe-pieces`.
In 2.x the workaround is to always assign a new object as `listProjection` when modifying it.
Contributor guide
Assessment
This issue has not been assessed yet.