Replies: 4 comments 4 replies
-
For the very first, I didnt thank's before to You for such huge efforts and jobs for this project, sorry, this one wonderfull and impressive. Due to you request for comments that planed changes, may I propose:
Moreover I suggest that could give really featured possibility to extends the ways how to present/display that value at the control panel, by hints, parameters, types or whatever else. Referring to (non-standard, but React's)
|
Beta Was this translation helpful? Give feedback.
-
@Kyr Thanks for offering your thoughts.
Unless I'm missing something, I don't know how you can distinguish reliably whether the default value is passed as the 2nd argument (new way) or as a
Indeed you can alias an import ( I know this is a breaking change but I am willing to keep the I'm just trying to find the perfect API going forward as I think an elegant signature is very important even if it seems like a detail. I know it's frustrating when library authors introduce breaking changes willy nilly but like I said I would keep the old API backwards compatible and also it's trivial for users to upgrade to the new API. We can create a simple codemod to help with that. So that being said, my question is, if we created this API today from scratch, what would it look like? |
Beta Was this translation helpful? Give feedback.
-
There's probably a way to work around the issue for TypeScript users such that when e.g. type ShortcutFixtureStateData<T extends FixtureStateData> = T extends { defaultValue: any } : never : T;
// Overloads
useValue<T extends FixtureStateData>(inputName: string, defaultValue: ShortcutFixtureStateData<T>): [T, SetValue<T>];
useValue<T extends FixtureStateData>(inputName: string, options: Opts<T>): [T, SetValue<T>];
// Implementation
useValue<T extends FixtureStateData>(inputName: string, options: Opts<T> | T): [T, SetValue<T>] {
// ... If `options` is an object with a `defaultValue` property, treat it as `Opts<T>` ...
} That's probably the wrong syntax, but something of that nature might work. Developers using JS only and using value objects that have a But if that doesn't work, then I think your proposal sounds reasonable. |
Beta Was this translation helpful? Give feedback.
-
After much thought and outside feedback I consolidated the fixture hooks into a concept called "Fixture Inputs" which is reflected in the updated docs. These are APIs that are meant to be used only inside fixtures, and they create interactive inputs in Cosmos' control panel that allow manipulating component data visually. The changes were published under version |
Beta Was this translation helpful? Give feedback.
-
I'm in the process of improving the API of
useValue
(and potentiallyuseSelect
).1) Accept default value as 2nd argument
At the moment the 2nd argument is an object with a
defaultValue
key. The original design was meant to allow future properties but we never added any and meanwhile the current API is more verbose than necessary.This cleans up the code and also makes
useValue
closer to the standarduseState
.2) Rename
useValue
touseCosmosState
First off, we pretty much need a new name for the
useValue
hook in order to preserve backwards compatibility when making change nr. 1. Because the default value could be an object with adefaultValue
key, there's no way to distinguish reliably between the new and old APIs.So while we're at it we might as well think of a better name going forward.
useCosmosState
has a couple of advantages:useValue
which could be present in other libraries or in the user's own codebase.useState
and it resembles the API used in other libraries (likeuseRecoilState
).Of course every change has potential disadvantages, for example:
useCosmosState
is longer and more likely to cause the expression to be multiline (although this is helped a lot by the first change which allows passing the default value directly as the 2nd argument).Feedback?
I'm pretty happy with both these changes and already made a tentative PR to see how the new API feels and you can tell by the diff it cleans up the code pretty nicely.
But I'd love to get your thoughts on this as well.
useSelect
touseCosmosSelect
too even though its API won't change, just for consistency? Are these hooks getting too verbose? What if we add more specific ones in the future likeuse[Cosmos]Slider
,use[Cosmos]Calendar
, etc.?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions