You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the issues with the current API of ReSift is that it's ambiguous which merge function will run when two fetch factories implement a merge from one namespace
import{defineFetch}from'resift';constmakeGetMovie=defineFetch({displayName: 'Get Movie',share: {namespace: 'movieItem',merge: {// this is merge 1 👇movieList: (prevMovie,nextMovieList)=>/* ... */,// 👆👆👆},},make: /* ... */,});
makeUpdateMovie.js
import{defineFetch}from'resift';constmakeUpdateMovie=defineFetch({displayName: 'Update Movie',share: {namespace: 'movieItem',merge: {// this is merge 2 👇movieList: (prevMovie,nextMovieList)=>/* ... */,// 👆👆👆},},});
So in this situation, there are 2 namespaces: movieList and movieItem and there are 3 fetch factories: getMovies, makeGetMovie, and makeUpdateMovie.
The ambiguity comes from the following question: when a SUCCESS occurs the movieList namespace (i.e. the getMovies fetch factory), which merge ("merge 1" or "merge 2") is ran?
The answer to this question is actually which ever merge was associated with a fetch factory that was dispatch last — a convoluted and weird answer.
Proposal
Instead of having the merges in the fetch factories, I propose we hoist them up to the <ResiftProvider> using a merges property. The convention would be to create a new file or folder called merges that will handle doing the merging from all namespaces to other namespaces.
constmerges={incomingNamespace: {destinationNamespace: /* ... mergeFunction ... */,},movieList: {movieItem: (previousMovieItem,nextMovieList)=>{// return a new movieItem using the `nextMovieList`}},};exportdefaultmerges;
The proposal is simple: instead of having the merges on the fetch factory, hoist them to the provider.
This will actually make the code much more simple. We can remove a lot of confusing logic in the reducers.
👆this code snippet is creating a lookup table of merge objects on FETCH so that it can correctly know how to merge in an incoming SUCCESS. If that sounds convoluted, it's because it is 😅.
If we hoist the merges to the provider level then we can deprecate this code and make things a bit more straightforward.
Summary
Problem: It's ambiguous which merge function will run when there is more than one merge function for the same source-target pairing of namespaces. Solution/Proposal: Hoist the merges definition to the provider. API Changes:share.merge will be deprecated (or possibly removed if possible) in favor of adding a merges prop to the <ResiftProvider> component.
The text was updated successfully, but these errors were encountered:
ricokahler
added
the
proposal
This contains a proposal for a feature or fix. This work may be subject to be discarded.
label
Dec 3, 2019
Problem
One of the issues with the current API of ReSift is that it's ambiguous which
merge
function will run when two fetch factories implement a merge from one namespaceFor example:
getMovies.js
makeGetMovie.js
makeUpdateMovie.js
So in this situation, there are 2 namespaces:
movieList
andmovieItem
and there are 3 fetch factories:getMovies
,makeGetMovie
, andmakeUpdateMovie
.The ambiguity comes from the following question: when a SUCCESS occurs the
movieList
namespace (i.e. thegetMovies
fetch factory), which merge ("merge 1" or "merge 2") is ran?The answer to this question is actually which ever merge was associated with a fetch factory that was dispatch last — a convoluted and weird answer.
Proposal
Instead of having the merges in the fetch factories, I propose we hoist them up to the
<ResiftProvider>
using amerges
property. The convention would be to create a new file or folder calledmerges
that will handle doing the merging from all namespaces to other namespaces.index.js
merges.js
The proposal is simple: instead of having the merges on the fetch factory, hoist them to the provider.
This will actually make the code much more simple. We can remove a lot of confusing logic in the reducers.
ReSift/src/dataServiceReducer/sharedReducer.js
Lines 23 to 31 in d0b6a1f
👆this code snippet is creating a lookup table of merge objects on
FETCH
so that it can correctly know how to merge in an incomingSUCCESS
. If that sounds convoluted, it's because it is 😅.If we hoist the merges to the provider level then we can deprecate this code and make things a bit more straightforward.
Summary
Problem: It's ambiguous which merge function will run when there is more than one merge function for the same source-target pairing of namespaces.
Solution/Proposal: Hoist the
merges
definition to the provider.API Changes:
share.merge
will be deprecated (or possibly removed if possible) in favor of adding amerges
prop to the<ResiftProvider>
component.The text was updated successfully, but these errors were encountered: