Comments (6)
In case you need to launch async process in your action dispatcher, consider emitting action upon completion of async call, and have another action dispatcher handle this action.
For instance, you might have UPDATE_ITEM action calling your REST API and ITEM_UPDATED action emitted upon success (and optionally ITEM_UPDATE_FAILED on failure).
This way the code is cleaner and easier to read and write tests against. With Uniflow, we encourage you to use actions as much as possible instead of using promises or callbacks.
from uniflow-polymer.
Thank you for ur advice. Can I further ask what would u recommend if I am waiting for multiple events to complete? (I am retrieving multiple resources)
E.g. I am using Promise.all now.
from uniflow-polymer.
Sorry, I am still pretty new to this. I am imagining a few solutions.
-
emit an action after each request, then the subsequent action will set a flag for the resource and check the state of all the other resources flags, and only emit a complete if everything is completed?
-
Wrap all requests inside 1 action and use a promise.all to emit a completed action?
from uniflow-polymer.
Sorry just one last question.
Should I keep the dispatched action (the object that is passed into the methods) immutable?
Because since each action is synchronous, if I allow the dispatched action to be mutable, I can use the action-dispatcher as middleware - modifying the data before updating the state.
from uniflow-polymer.
Very good questions.
As to waiting for multiple events to complete, we've implemented one solution in our internal version of the library. I think it's a bit too complex and specific, so I wasn't sure about porting it to open-sourced repo. It's quite close to what you're describing in your option (1), though.
For your second question about keeping action property object immutable the answer is simple: you don't have to, and in fact you can have multiple action dispatchers acting like middleware and updating action object with new information for future actions. The order in which actions are processed is defined by the order dispatchers are declared.
from uniflow-polymer.
Thank you very much!
from uniflow-polymer.
Related Issues (14)
- Where to call server api HOT 4
- Question: Does uniflow support using uniflow sub components? HOT 1
- Update to Polymer 2.0 HOT 4
- Access to state in state aware element HOT 3
- Polymer 3 HOT 2
- Would it be possible to release a first version HOT 2
- Making a uniflow version of the Starter Kit app HOT 3
- app-router integration HOT 9
- Sample application HOT 2
- bower polymer-uniflow-a HOT 2
- Support for Polymer 2.0 HOT 3
- Possible to use with "polymer build"? HOT 2
- Difference between UniFlow and PolymerRedux HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uniflow-polymer.