Skip to content

Generalize and extend API#4

Open
ArtemyB wants to merge 5 commits into
SelectViewData:mainfrom
ArtemyB:feat/extend-api
Open

Generalize and extend API#4
ArtemyB wants to merge 5 commits into
SelectViewData:mainfrom
ArtemyB:feat/extend-api

Conversation

@ArtemyB
Copy link
Copy Markdown

@ArtemyB ArtemyB commented Aug 26, 2024

N.B. This PR also includes the commits from #3, so if this PR is viable, I suppose It'd be easier to accept it right away, ignoring PR #3.

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 ElmishStoresHost type with generic store key, as a replacement for ElmishStore module

  • Replace ElmishStore module that statically defines Stores registry, with ElmishStoresHost type 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 uniqueName string parameter used as store key is replaced with a generically defined storeKey parameter. This gives possibility use any type (that fits equality constraint) as a store's key, not only string. For example, GUID, or a custom DU type value.

2. Introduce StoreApi module

The module defines IElmishStoreApi interface to represent an object that incapsulates the ElmishStore itself and a set of selector hooks on the ElmishStore instance.
Also, the module provides:

  • getElmishStoreApi function that returns an object with IElmishStoreApi value.
  • useElmishStoreApi hook that just memoizes getElmishStoreApi result.

This API allows to create all the Store instance related hooks at once, instead of defining them one by one manually.

ArtemyB added 5 commits August 9, 2024 16:26
- 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.
@ArtemyB ArtemyB marked this pull request as ready for review August 26, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant