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

Open
#2,416 0 comments 0 reactions 1 assignee Claimed by @boutell View on GitHub
enhancement v3
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.