Closed ScreamZ closed 3 years ago
Thanks for your suggestion Andréas.
I think you make some valid points. With a proclivity to "static typing", your suggestions make a lot of sense.
With that said, it really comes down to a personal preference. Granted, your suggestions play better for static types.
However, I still prefer the current API with it's overloaded functionality, as it provides a very concise way to extract multiple aspects in a single invocation. Obviously, you are free to disagree.
Your example of passing a withKeys
parameter directive would force it to be applicable to all fassets in question (for that invocation) ... when using the "3rd form" (see below).
Providing two useFassets() APIs (singular/plural) to distinguish wildcard support, would require them to error out when the invoker did not conform to the wildcard requirements. In my mind it is better for a single API to interpret whether wildcards were provided, and adjust appropriately.
The useFassets() API currently takes on 3 distinct forms. This may be an anti-pattern to some (and problematic in in strongly typed definitions), but I actually prefer the way it currently operates.
Per the the docs (https://feature-u.js.org/cur/api.html#useFassets):
+ useFassets(): fassets ... the full Fassets object
+ useFassets(fassetsKey): fassetResource | fassetResource[] (array used when wildcards are found in fassetsKey)
+ useFassets(mapFassetsToPropsStruct): {key1: fassetResource, key2: fassetResource ... }
The second case is identical to the get() method of the Fassets object ... https://feature-u.js.org/cur/api.html#Fassets_get
The third case allows you to retrieve multiple keys with one invocation.
The API in the docs give more examples.
BTW: Just an FYI - I'm am not going to want to promote a formal TypeScript mapping directly in the feature-u project, for a variety of reasons.
The major issue is one of time. As I mentioned, I have never used TypeScript, and this is not something that is on my radar at the moment.
Hi kevin,
working on feature-u typescript implementation as I already discussed by e-mail with you :)
Currently, if you need to get assets with keys, you need to add a prefix with
@withKeys
. I guess it's too magic and it doesn't work well with types based solutions.A better approach could be to pass an argument to the hooks or HOC.
const Element = useFassets("some.content",true)
where true is an optional parameter with defaultfalse
. That allows to get keys.Also, we might consider
useFasset
anduseFassets
for wildcard support. That could allow to not cast result with typescript to consider it as an array.What do you think about that?
Regards, Andréas