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
Even if the promise do not supports the progress callback, the first call of it can be useful to determine that we must display some kind of gif-spinner.
Usage example:
// Post ReducersconstdisplayPostReducer=handleAction('DISPLAY_POST',(state,action)=>{// do something for display post})constupdatePostReducer=handleAction('UPDATE_POST',(state,action)=>{// do something for update post})constdeletePostReducer=handleAction('DELETE_POST',(state,action)=>{// do something for delete post})constprogressTypes=['DISPLAY_POST','UPDATE_POST','DELETE_POST']consthandleProgress=handleProgress(progressTypes,(state,{ type, meta })=>{// This callback will be runned only if (action.progress == true)return(type=='UPDATE_POST'||action.type=='DELETE_POST')// If it's an update or delete action, then we must block form// only if the current post is the same with the deleted/updated post
? { ...state,progress: (state.post.id==meta.id)}
: { ...state,progress: true}})constpostReducer=(state={post: null,progress: false},action)=>{state=handleProgress(state,action)if(state.progress){returnstate}state=displayPostReducer(state,action)state=updatePostReducer(state,action)state=deletePostReducer(state,action)returnstate}// Post ActionsconstbuildMeta=(id)=>{id}constdisplayPost=createAction('DISPLAY_POST',(id)=>api.getById(id),buildMeta)constupdatePost=createAction('UPDATE_POST',(id,data)=>api.update(id,data),buildMeta)constdeletePost=createAction('DELETE_POST',(id)=>api.delete(id),buildMeta)// Post ComponentsclassPostGridextendsComponent{// ...render(){const{ posts, displayPost, deletePost }=this.propsreturn(<table>{_.map(posts,(post)=><tronClick={()=>displayPost(post.id)}><td>{post.title}</td><tdonClick={()=>deletePost(post.id)}>Delete</td></tr>)}</table>)}}
@connect(state=>({post: state.post,progress: state.progress}))classPostFormextendsComponent{// ...render(){const{ progress, post }=this.propsif(progress){// display the gif-spinner }// ...}}
The text was updated successfully, but these errors were encountered:
Hi. The Promise middleware is very cool, but what if we add the progress tracking too? It may looks like this:
Even if the promise do not supports the progress callback, the first call of it can be useful to determine that we must display some kind of gif-spinner.
Usage example:
The text was updated successfully, but these errors were encountered: