Patterns icon indicating copy to clipboard operation
Patterns copied to clipboard

Pattern defaults are controlled by `inherit` in ArgumentParser.parse()

Open fulv opened this issue 7 years ago • 2 comments

Here are the first eight lines of ArgumentParser.parse():

    parse: function argParserParse($el, options, multiple, inherit) {
        if (typeof options==="boolean" && multiple===undefined) {
            multiple=options;
            options={};
        }
        inherit = (inherit!==false);
        var stack = inherit ? [[this._defaults($el)]] : [[{}]];
        var $possible_config_providers = inherit ? $el.parents().andSelf() : $el,
            final_length = 1;
  1. By default (i.e. if one does not pass an inherit argument to parse()), inherit is set to true. In other words, inheriting is enabled by default. This is probably a design decision that I assume makes sense.
  2. However, inherit also controls whether a pattern's defaults should be used (line with var stack =...).

Thus, if one wants to disable inheritance from DOM parents, one also loses all the defaults set in the pattern (e.g. parser.addArgument(...)). And viceversa: if I wanted to omit the defaults in my pattern, I would not be able to inherit some values from the element's parents.

What is the justification for this choice of overloading inherit?

fulv avatar Oct 24 '18 10:10 fulv

@fulv I fear I can't answer that question, I believe that was done way ago by Wichert. What is the impact of not answering this?

pilz avatar Feb 28 '20 10:02 pilz

I guess what I was really asking was whether it would make sense to decouple the parent inheritance from the local defaults. But I imagine it might be hard to assess the impact of such a change.

Fulvio

On Fri, Feb 28, 2020 at 2:23 AM Alexander Pilz [email protected] wrote:

@fulv https://github.com/fulv I fear I can't answer that question, I believe that was done way ago by Wichert. What is the impact of not answering this?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Patternslib/Patterns/issues/627?email_source=notifications&email_token=AADQPRSXDCULQPTG3WMHSCLRFDQYJA5CNFSM4F66MEFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENIA3BY#issuecomment-592448903, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQPRWHAY6X5TJL4JEH4PDRFDQYJANCNFSM4F66MEFA .

fulv avatar Feb 28 '20 20:02 fulv