Generalize and extend API#4
Open
ArtemyB wants to merge 5 commits into
Open
Conversation
- Introduce `Hooks` module with all the hooks moved there instead of being defined in the `React` type. This way, the generated JS is cleaner because module function names aren't mangled. - Move `React` inline type extensions to a separate "Extensions" file. - Remove `Hook` attributes from inline functions for their irrelevance.
- Target .NET 6 instead of .NET 8 to relax package requirements. - Relax "FSharp.Core" dependency to v6. - Introduce "Fable.Package.SDK" package to facilitate project configuration for Fable. - Bump package version to 0.2.1. - [Example] Update "Feliz" to v2.8.0, update Fable to v4.7.0.
- Introduce `ElmishStoresHost` type with a bunch of related interfaces, as a replacement of the `ElmishStore` module. This allows controlling creation of the "store root" (instead of hard-coding it in the module). - Replace `uniqueName` string parameter, for a store key with a `storeKey` parameter of a generic type. This allows using any type as a key, including `string`.
`StoreApi` module defines: - `getElmishStoreApi` function that returns an object with `ElmishStore` and a set of selector hooks on that store. - `useElmishStoreApi` hook that just memoizes `getElmishStoreApi` result.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All these changes essentially just generalize and extend the API, permitting the previous usage as well. The example is also updated to use the new API.
1. Introduce
ElmishStoresHosttype with generic store key, as a replacement forElmishStoremoduleReplace
ElmishStoremodule that statically defines Stores registry, withElmishStoresHosttype that incapsulates the registry. This allows manually defining Stores "root" in any place of an application.For example, it should allow defining store's root inside React context. Technically, this should give possibility to use many Stores with the same key if they're defined inside different Context Providers, where each Context Provider creates a new instance of
ElmishStoresHost. Don't know if this is a good solution, and maybe it's better to handle this through a single host and different generated Store keys.The
uniqueNamestring parameter used as store key is replaced with a generically definedstoreKeyparameter. This gives possibility use any type (that fitsequalityconstraint) as a store's key, not onlystring. For example, GUID, or a custom DU type value.2. Introduce
StoreApimoduleThe module defines
IElmishStoreApiinterface to represent an object that incapsulates theElmishStoreitself and a set of selector hooks on theElmishStoreinstance.Also, the module provides:
getElmishStoreApifunction that returns an object withIElmishStoreApivalue.useElmishStoreApihook that just memoizesgetElmishStoreApiresult.This API allows to create all the Store instance related hooks at once, instead of defining them one by one manually.