Closed lifeart closed 5 years ago
Sounds reasonable to me! I think this would be a great thing to add support for.
Maybe a regex and / or predicate function would be more flexible?
@buschtoens do you have thoughts on what the API to whitelist additional attributes might look like with those suggestions?
Nothing concrete, no. I guess that we would want this setting to live in the config/environment.js
, another file in config/
or ember-cli-build.js
.
'@ember-decorators/argument': {
whitelist: [
/^hotReloadCUSTOM/,
key => key.startsWith('hotReloadCUSTOM')
]
}
I think you can't easily have non-primitive values in config/environment.js
though. So maybe some extra file would be required.
or it can be array of plain strings with startsWith
logic.
whitelist: ['bs-', 'hotReloadCUSTOM', 'liquid-fire']
@lifeart sure, that's what it would be for prefixes only.
prefixes + full names.
or
whitelist: { startsWith: ['-bs'], includes: ['-dummy'], endsWith: ['-form'] }
I think a regex approach is probably the easiest way to go — very flexible and easy to express exact match, starting with, ending with, etc.
Ugh... So, neither functions nor regular expressions actually are translated through the config/environment.js
file correctly. Regular expressions come through as {}
and a function came through as null
.
I'm going to approach this by allowing either of these:
// array of exact matches
attributeWhitelist: ['foo']
or
// define how you want to match
attributeWhitelist: {
startsWith: [],
includes: [],
endsWith: []
matches: []
}
If we can figure out a way to handle regular expressions, I would love to simplify that, but that's the plan for now.
regexp in config can be in string form, and we can do new RegExp(string)
; as mentioned in https://github.com/ember-decorators/argument/pull/91/files#diff-164d647270288733c95f5bd657121df7R23
Yup, that's basically what my PR does! Each of the different keys in the object-style whitelist creates the RegExp
a different way.
should we have few params or just allow users to specify regexp string body in config?
attributeWhitelist: ['^$fooBar', '$-form$', 'exact']
Hmm, yeah that might make more sense. My only worry would be that it’s a little hard to explain what’s required — saying “put a regex in the string” will likely lead to some people accidentally putting a regex in there, which will break. On the other hand, simpler code and a cleaner API... Not sure which I like better, would love other opinions!
Is this addon still a no-op in production builds? In this case, we might want an extra file instead, which would allow us to import it as is and even strip it from production builds.
@alexlafroscia it can be kinda "hidden" feature, noted in *
. By default we can specify it should be full names: attributeWhitelist: ['someProperty', 'isEnabled', 'astHOTLOAD']
and only power users may know it may be an stringed regexp )
also, it can be path-like
item. attributeWhitelist: ['bsDropdown.readOnly']
where bsDropdown
=== component.constructor.name || component._debugContainerKey || component.toString()
Is this addon still a no-op in production builds?
Yup, even more so in 1.0.0
where all of the behavior is stripped in production. The pre-1.0.0
version key a small amount of runtime behavior in production builds but stripped most of it. That behavior is built into ember 3.4+
now, so we're aligning with that.
In this case, we might want an extra file instead, which would allow us to import it as is and even strip it from production builds.
I'm not sure what you mean -- could you explain?
Yes, sure! I mean something like config/ember-intl.js
. While in this case the file is require
d by Node, we could easily make it part of the build pipeline. Alternatively, we could do it like liquid-fire's transitions.js
and put the file at the root of the app
.
Interesting -- I think I like the idea of doing something like config/ember-decorators/arguments.js
(or something else in the config
directory) better. I personally don't love putting a config file in app
.
During Handlebars AST compile time I add few props for component invocation:
hotReloadCUSTOMhlContext
,hotReloadCUSTOMName
,hotReloadCUSTOMhlProperty
,hotReloadCUSTOMHasParams
,hotReloadCUSTOMHasHash
,is it possible to whitelist it by prefix?
hotReloadCUSTOM
or allow users to add it into addon config