Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Declarative redux promise middleware

NotificationsYou must be signed in to change notification settings

Tracktl/redux-promise-middleware

Repository files navigation

Conventional Commits

Install

npm install --save @tracktl/redux-promise-middleware

or

yarn add @tracktl/redux-promise-middleware

Usage

Create promise implementations:

constAPI=Symbol('API');constimplementations=newMap([[API,action=>{if(process.env.NODE_ENV!=='production'){if(typeofaction.endpoint!=='string'){thrownewError('Expected endpoint to be a string.');}}returnfetch(action.endpoint);},]]);

Add it as a middleware:

import{createStore,applyMiddleware}from'redux';importcreatePromiseMiddlewarefrom'@tracktl/redux-promise-middleware';conststore=createStore(reducer,applyMiddleware(createPromiseMiddleware(implementations)))

Dispatch an action

store.dispatch({promise:API,endpoint:'/movies'types:['movies/get:fetching','movies/get:success','movies/get:fail'],// optional metasmetas:[null,null,null],});

Local Development

Below is a list of commands you will probably find useful.

npm start oryarn start

Runs the project in development/watch mode.

npm run build oryarn build

Bundles the package to thedist folder.The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test oryarn test

Runs the test watcher (Jest) in an interactive mode.By default, runs tests related to files changed since the last commit.

About

Declarative redux promise middleware

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp