Open xinaesthete opened 9 months ago
@xinaesthete We will accept the PR. I will review soon.
Another thing you might want to check as you review is whether the 'equality function' stuff looks right & isn't applied in the wrong way anywhere. That part of the PR was because of Zustand warnings but I suppose could be a place where there's potential for me to've done something sub-optimal, or that might need to change yet again with subsequent Zustand update (https://github.com/pmndrs/zustand/discussions/1937). Anyway, if anything does need to change now or in future, it will be in a very focused part of the code I believe.
Background
This refactors to use React Context, as a step towards allowing more of Avivator to be used as a library, as per #745
Change List
<AvivatorProvider>
is used in index.jsxexport const useXxxStore = create(...)
becomesconst createXxxStore = () => createStore(...)
, with correspondinguse
declarations further down. I think this change looks bigger in diff than it might otherwise because of prettier formatting.useXxxStoreApi
have been added, which access the context and return a reference to the given store. This is used by new versions of theuseXxxStore
hooks (which also wrapuseStoreWithEqualityFn
as per deprecation warnings from Zustand), as well as anywhere thatuseXxxStore.setState(...)
was previously used, as it's not possible to determine which context should be used outside React rendering (event callbacks etc).To the best of my knowledge this doesn't impact functionality or performance - pretty sure the current pattern doesn't incur any extra renders or unnecessarily expensive Zustand calls, but I could be mistaken.
I've run tests/lint etc as well as manually testing most features in the Avivator UI.
Checklist