Giter VIP home page Giter VIP logo

reflux-promise's People

Contributors

benknight avatar devinivy avatar hubertlepicki avatar levrik avatar semikolon avatar spoike avatar

Stargazers

 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

reflux-promise's Issues

reflux-promise causes triggerAsync to actually execute synchronously

Reading the source code, I can see that including this library overrides reflux-core's triggerAsync with reflux-promise's triggerPromise.

However, at least when using window.Promise, the executor function passed to the Promise constructor executes immediately, before the constructor returns the created object (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)

So that means the following code is executing immediately when an action is triggered async:

me.trigger.apply(me, args);

https://github.com/reflux/reflux-promise/blob/master/src/index.js#L55

This is causing issues when upgrading Reflux on my project because I have code that depends on actions executing on the "next tick". For example, calling an action in componentWillMount, which causes my store to trigger synchronously, but doesn't update the component because Reflux.connect attaches the listener in componentDidMount.

Using triggerPromise I only receive one argument in `.then`?

Reported by @ponelat in reflux/refluxjs#416

When I have a triggerPromise... I only receive the first argument in then clause.

var someAction = Reflux.createAction({asyncResult: true});
someAction.listen(function(a,b,c) {
  someAction.completed(a + '-eh', b + '-eh', c + '-eh')
})

someAction.triggerPromise(a,b,c)
  .then(function(d,e,f) { // Assume d,e,f are passed into 
    console.log(d,e,f) // <- Only d is defined
  })
.catch(function() {})

I've looked into the source and I'm not sure why this is assumed to be an array of args?... https://github.com/reflux/reflux-core/blob/master/src/PublisherMethods.js#L159

Could be a bug, or it might be me. I can PR if I get some time, but otherwise help is always appreciated!

Promises outcomes are mixed up.

Maybe I didn't understand the purpose of this lib, but I think there is something wrong in the way it manages Promises.

When an action is triggered, the returned Promise object should be resolved or *rejected" according to the outcome of the triggered action.

The point is that RefluxPromise completly ignores Promised objects returned by an action handler. Instead, it creates its own Promise which is resolved / rejected whenever the completed / failed methods of the action are called. At anytime.

In otherwords, when an action is called, it does not return a promise of the outcome of this action, but a promise of the outcome of any similar action.

For instance...

I'm using a Reflux store to persist changes on DB using a REST service. If the service fails (for whatever reason), I want to know which action couldn't make it. That's why I wanted to used Promises.

So I would like to do the following:

var actions = {
    'change': Reflux.createAction({ asyncResult: true })
};

Reflux.createStore({
    listenables: actions,

    onChange: function(data) {
        return RestPromises.jsonPost('/my_service', data)
    },
})

changePromise = actions.change({foo: 'bar'});

But it doesn't work ! changePromise is not the Promise returned by jsonPost, but a Promise created by Reflux-Promise which is actually always resolved.

So I had to do the following instead:

var actions = {
    'change': Reflux.createAction({ asyncResult: true })
};

Reflux.createStore({
    listenables: actions,

    onChange: function(data) {
        return RestPromises.jsonPost('/my_service', data)
            .then(function () {
                actions.change.completed();
            })
            .catch(function (error) {
                actions.change.failed(error);
            });
    },
})

But then, when I trigger the same action 2 times...

changePromise_1 = actions.change({foo: 'good'});
changePromise_2 = actions.change('bad');

... they will get the same outcome, and will be both rejected or resolved ! Obviously this is not a desired behavior.

triggerPromise and Bluebird 3.0 warnings

I recently updated all the packages in a project and now I'm getting a lot of long noisy warnings from Bluebird:

"Warning: a promise was created in a handler but was not returned from it"

at triggerPromise from Object.functor (stack dump meaningless because it's a browserified bundle)

The Bluebird docs state that if you want to do this intentionally without a warning, you have to return a value (such as null) from the parent. Any chance of implementing this behavior? The only option for a consumer is to disable such warnings globally, and for obvious reasons that's undesirable.

Pass params in listenAndPromise

support.jsx

.....
fetchData = () => {
        var params = {
            'internshipbuffer':this.state.buffer_id
        }
        supportAction.getMessage(params).then(this.updateData)
    }
.....

supportAction.jsx

import Reflux from 'reflux'
import supportResource from '../resources/supportResource'

var actions = Reflux.createActions({
    'getMessage': {
        children: ['completed', 'failed']
    }
});

actions.getMessage.listenAndPromise(supportResource.getMessage(params));

export default actions;

supportResource.jsx

import Api from '../util/api'

var supportResource = {
    getMessage(params) {
        return Api.get('/internshipbuffer/getChat', params);
    }
}

export default supportResource;

I am getting an error in supportAction.jsx :-

params is not defined

How to pass params to the resource ?
If i don't pass params i am getting undefined response

Reflux actions throw an error in the console when they fail

Originally posted by @liady reflux/refluxjs#403 Moved to here since promises have been extracted out of reflux-core and is now in reflux-promise.

Lately I started getting Uncaught (in promise) some-error errors in my console whenever an action failed.
I researched a bit and found out that Reflux creates a promise every time an action is triggered, and if the action fails, the promise rejects and there is no one to catch it. I boiled it down to:

// create an action with completed/failed children
var action = Reflux.createAction({asyncResult:true});

// *** First scenario - throws error *** //
// invoke the action
action();
// somewhere the action has failed
action.failed("some reason"); // throws an error in the console - why??


// *** Second scenario - ok *** //
// invoke the action, but with a catch clause
action().catch(function(){});
// somewhere the action has failed
action.failed("some reason 2"); // this is now ok...

Fiddle here

Seems like every action trigger creates a promise, and that causes this issue when the action fails. I would imagine this would happen only when calling action.triggerPromise explicitly, and not every time.

Currently I have to attach a catch clause to every action trigger in my code to fix this problem. I want my components to just call the actions, not handle their outcome. Is there a way to avoid it? Am I missing something here?

Looking for maintainers

Due to a change of priorities and busy work days I have to do what most OSS projects do and seek for active maintainers that can bring the project forward and get the ball rolling for more helpful features to be released.

As much as I'd like to put my heart and mind into reflux, there simply is no time for me to do so. However it'd be a shame for me to put this project on indefinite limbo for several reasons:

  • The libraries are still actively used, with reflux by itself having more than 11 000 downloads per week on npm.
  • Users are generally appreciative for reflux's super-easy API, contrary to the other popular flux-but-not-really framework cough redux cough cough. 😉

If you have and like to spend some time working on developing reflux and managing the community on github further, let me know on e-mail (check my profile) and we'll take it from there. Contributors who have done PR in the reflux projects are preferred.

Errors thrown in listeneners (onSomeActionCompleted, for eg) fail silently.

This is not ideal.
I understand it was an irritation when failed actions propagated to the console as errors. But I feel this is worse.

if I have ....

onSomeActionCompleted() {
   throw new Error("hello?")
}

execution just stops. No errors appear in the console.

Is there perhaps a way to configure reflux ( or reflux-promise ) to handle the promise in a more explicit manner?

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.