Git Product home page Git Product logo

redux-promise-listener's People

Contributors

bristoljon avatar erikras avatar gausie avatar iharthi avatar jfreixa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redux-promise-listener's Issues

Multiple requests get resolved with the first one which succeeds

If I fire up multiple requests where each request takes some time before it gets resolved all requests are getting resolved with the first request which succeeds.

async getUser(request) {
  return new Promise(resolve => {
    const generatedAsyncFunction = promiseListener.generateAsyncFunction({
      start: 'START_ACTION_TYPE',
      resolve: 'RESOLVE_ACTION_TYPE',
      reject: 'REJECT_ACTION_TYPE'
    });

    generatedAsyncFunction.asyncFunction({ request }).then(
      resolvePayload => {
        resolve(resolvePayload);
      },

      rejectPayload => {
        resolve(rejectPayload);
      }
    )
  });
};

// All requests are getting resolved with A
getUser('A').then(console.log);
getUser('B').then(console.log);
getUser('C').then(console.log);

Uncaught (in promise) errors

Are you submitting a bug report or a feature request?

This is a bug report.

What is the current behavior?

When a promise is rejected the error is not being caught.

What is the expected behavior?

The error being caught.

Sandbox Link

https://codesandbox.io/s/qqwn5vn1rj

What's your environment?

I'm using redux-promise-listener v1.1.0 and react-redux-promise-listener v1.0.0

Other information

I've described the issue here also.

Add typescript types declaration

Hi,

redux-promise-listener doesn't have typescript type definitions at the moment. I tried to convert existing flow type definitions and I ended up with this:

declare module 'redux-promise-listener' {

    import { Store } from 'redux';

    export type State = any;

    export interface Action {
        type: string;
        payload?: any;
    }

    export type Next = (action: Action) => State;

    export type SetPayload = (action: Action, payload: any) => Action;

    export type GetPayload = (action: Action) => any;

    // I'm not sure about this generic
    export type Middleware<S = any> = (store: Store<S>) => (
        (next: Next) => (
            (action: Action) => State
        )
    );

    export interface Config {
        start: string;
        resolve: string;
        reject: string;
        setPayload?: SetPayload;
        getPayload?: GetPayload;
        getError?: GetPayload;
    }


    export interface AsyncFunction {
        asyncFunction: (...args: Array<any>) => Promise<any>;
        unsubscribe: () => void;
    }


    export type PromiseListener = {
        middleware: Middleware,
        createAsyncFunction: (config: Config) => AsyncFunction
    };


    export default function createListener(): PromiseListener;

}

I'm not proposing a pull request because I'm not sure if this declaration is correct and whether you find this idea useful.

Thank you.

Upgrade react version

@erikras Hey there! Just interested that if I increase the support of react in package.json would you consider merging it? It would help out with migration from react 16 projects to higher versions.

Error: "Actions may not have an undefined "type" property.

Are you submitting a bug report or a feature request?

bug report

What is the current behavior?

I use the provided code of step 1 and step 2 and get the following error:
Error: "Actions may not have an undefined "type" property. Have you misspelled a constant?".

          const generatedAsyncFunction = promiseListener.createAsyncFunction(
            'START_ACTION_TYPE',
            'RESOLVE_ACTION_TYPE',
            'REJECT_ACTION_TYPE',
          );

          const values = {
            type: REQUEST_ITEMS,
            payload: { eventName, request },
          };

          generatedAsyncFunction.asyncFunction(values).then(
            resolvePayload => {
              console.log('foo: ', resolvePayload);
            },

            rejectPayload => {
              console.log('bar: ', rejectPayload);
            },
          );

          generatedAsyncFunction.unsubscribe();

What is the expected behavior?

To not get an error.

What's your environment?

node: 8.12.0
redux-promise-listener: 1.1.0
macOS: 10.13.6

Other information

Error: "Actions may not have an undefined "type" property. Have you misspelled a constant?"
performAction http://localhost:8080/:1:40951
liftAction http://localhost:8080/:1:34375
dispatch http://localhost:8080/:1:38408
middleware webpack:///./node_modules/redux-promise-listener/dist/redux-promise-listener.es.js?:46:16
sagaMiddleware webpack:///./node_modules/redux-saga/dist/redux-saga-core.esm.js?:1414:22
dispatch webpack:///./node_modules/redux/es/redux.js?:571:18
asyncFunction webpack:///./node_modules/redux-promise-listener/dist/redux-promise-listener.es.js?:61:9
asyncFunction webpack:///./node_modules/redux-promise-listener/dist/redux-promise-listener.es.js?:60:14
t0 webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:608:19
Promise webpack:///./node_modules/core-js/library/modules/es6.promise.js?:177:7
_callee11$ webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:594:33
tryCatch webpack:///./node_modules/regenerator-runtime/runtime.js?:62:37
invoke webpack:///./node_modules/regenerator-runtime/runtime.js?:288:22
method webpack:///./node_modules/regenerator-runtime/runtime.js?:114:16
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:5:24
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:27:9
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:34:7
Promise webpack:///./node_modules/core-js/library/modules/es6.promise.js?:177:7
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:23:12
_emit webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:665:16
_callee$ webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:86:24
tryCatch webpack:///./node_modules/regenerator-runtime/runtime.js?:62:37
invoke webpack:///./node_modules/regenerator-runtime/runtime.js?:288:22
method webpack:///./node_modules/regenerator-runtime/runtime.js?:114:16
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:5:24
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:27:9
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:34:7
Promise webpack:///./node_modules/core-js/library/modules/es6.promise.js?:177:7
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:23:12
request webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:102:16
_callee4$ webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:187:24
tryCatch webpack:///./node_modules/regenerator-runtime/runtime.js?:62:37
invoke webpack:///./node_modules/regenerator-runtime/runtime.js?:288:22
method webpack:///./node_modules/regenerator-runtime/runtime.js?:114:16
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:5:24
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:27:9
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:34:7
Promise webpack:///./node_modules/core-js/library/modules/es6.promise.js?:177:7
node_modules babel/runtime-corejs2/helpers/asyncToGenerator.js?:23:12
PUT webpack:///./src/rumo-socket.js?./node_modules/babel-loader/lib:206:16
Scratchpad/1:55:9

Provide more granular control over trigger actions

FEATURE REQUEST

Hi,

This would be great for us to get the full benefit out of redux-form whilst using redux-saga but unfortunately we need more fine tuned control over the actions that will resolve or reject the promise.

The reason is, we have a custom api request handling thing that uses generic API_REQUEST, REQUEST_PENDING, REQUEST_SUCCESS etc. action types with the specific endpoint and params requested stored under a meta key.

So we need to be able to resolve or reject the promise by looking at the whole action. How about making generateAsyncFunction take optional function for customising the behaviour?

const generatedAsyncFunction = promiseListener.generateAsyncFunction(
  'START_ACTION_TYPE',
 action => action.type === 'REQUEST_SUCCESS' && action.meta.endpoint = '/api/v3/users',
 action => action.type === 'REQUEST_FAILED' && action.meta.endpoint = '/api/v3/users',
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.