Move declaration of replacements and selectors to new function #815
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Move declaration of replacements and selectors to new function
At present the declaration of all raw un-processed selectors and their
replacements is in either the class body (private vars) or the
constructor.
This has the effect of modifying the original selectors on the class
instance vars during class instantiation, and also prevents any subclass
of ExactNamedSelector or PartialNamedSelector from making changes to any
replacement that has been explicitly overridden in those classes
constructors.
For example, it is impossible for a child class of either of these to
further override the '%tagTextMatch%' replacement because those changes
would either be overridden in the constructor of its parent, or all
original selector replacements would not be applied.
Furthermore the original values of both the selectors and replacements
have been mutated in the constructor so it is not possible for any child
class to simply re-apply the original translations.
The only solution to this problem is to extend the NamedSelector base
class and manually copy the standard replacements from
PartialNamedSelector or ExactNamedSelector (as appropriate) into your
new child class, but this approach is not sustainable.
This patch modifies the Selector classes to:
untranslated selectors and replacements to a function. This
effectively makes them immutable; and
and replacements by simply overriding the parent class function and
updating or adding the required array values.
This change allows the replacements (or selectors) to be updated as in
the following example:
Note: For any usage where the child class was directly extending the
NamedSelectorclass and defining its custom selectors and replacementsin the constructor, these will need to be updated to define the relevant
getRawSelectors()and/orgetRawReplacements()classes as above.This change should be considered a possibly breaking change in this
situation and therefore would demand a new major release (1.10.0
presumably).
Whilst this is a breaking change, it will have provide a more
sustainable approach in future for more advanced uses of Mink.