-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export store's useful typescript definitions - close #5864 #5887
Conversation
the store has some internal types that are useful and should be exported to help consumer apps typing their store implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exports "missing" store types. If there are no side effects that are not know to me this should be great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same was already proposed in #5170, and @Conduitry said that he doesn't want to expose Invalidator
and StartStopNotifier
as these are internal API. So we would at least need to remove these two from the exports.
I have removed the exports for those 2 types. Also trying to have some careful thought about the other types of the store. On one hand, they're helpful, on the other hand, I can get around the limitation of not exporting them by writing code as such: /**
* Instead of:
* getCoinList: StartStopNotifier<ReadonlyArray<CoinMarketData>> = (
* set: Subscriber<Date>
* ) => {
* ...
*
* set(...)
* }
*
* Write like this:
*/
async function getCoinList(): Promise<ReadonlyArray<CoinMarketData>> {
const res = await fetch(
'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd'
);
if (!res.ok) {
throw new Error(await res.text());
}
const markets = await res.json();
return createFormattedCurrencyFields(markets);
}
export const coinMarket: Readable<CoinMarketDataStore> = readable(
initialValue,
(set) => {
(async () => {
try {
/**
* Don't need to call getCoinList(set)
*/
const markets = await getCoinList();
set({
markets,
error: null,
});
} catch (error) {
set({
markets: [],
error,
});
}
})();
return function stop() {
// nothing
};
}
); What do you think? Does it look like this is the recommended approach rather than exporting the types or we should still export those types for other use cases? |
I gotta reverse my opinion on |
@dummdidumm could you tell what blocks this PR? let's rebase it and merge, why we're awaiting from January? |
Close #5864
The store has some internal types that are useful and should be exported to help consumer apps typing their store implementations. See more in #5864
Before submitting the PR, please make sure you do the following
Tests
npm test
and lint the project withnpm run lint