Comments (3)
Requests should not block. What you probably want is throttling that will put concurrent requests on hold and then respond with the cached response when the first request completes.
from amplify.
Sorry; "block" was a misleading word. The idea is that the request is not being 'blocked' in the async sense, but rather the request is added to a queue rather than submitting multiple duplicate AJAX requests. Here's some rough code:
function request(resource_name, callback) {
this_request = some_lookup_of_requests.get(resource_name);
if this_request.is_outstanding(resource_name) {
// by outstanding - the request has been made, and a response not
// yet received
subscribe(this_request, callback);
// when the ajax returns, the results are published
} else {
amplify.request(resource_name, function (...) {
this_request.no_longer_outstanding();
// make sure that subsequent requests do not subscribe when
// no ajax request is outstanding
callback(...); // tell the caller
publish(this_request, ...); // notify any subscribers
});
}
}
This is not really caching in the traditional sense; it may be better to describe it as a subscriber/publisher alternative to multiple concurrent requests.
I am not sure if this is something amplify.js
would want - but since it reduces the need for developers to think about the need for multiple concurrent requests I tend to think it is helpful - but in any case I hope the above clarifies what I had intended.
Plus it's fun. :)
Cheers.
from amplify.
I am facing the same problem. It would be very cool to have such a mechanisms. Or how it be implemented on our own? Any hints?
from amplify.
Related Issues (20)
- Amplify 1.1.2 Uncaught TypeError in new Chrome
- Race condition in core.js publish method HOT 5
- Add browser support documentation [was: "IE8 support"] HOT 1
- amplify.js incompatible with FormData
- losing the data in local storage that I set on a HTTP page when I move to a HTTPS page HOT 1
- Subscribe to event groups (namespaces)
- is amplify still being developed? HOT 5
- null being passed to handleResponse on error instead of _xhr HOT 1
- Any plan to support chrome.storage in the future?
- Not an issue, a suggestion... for pubsub HOT 1
- support for commonjs HOT 1
- amplify.store() examples in the docs is not working HOT 1
- ajax request types are taking longer than default jquery ajax calls
- need clear all subscription method
- Publish core as a separate module
- Offline DB Support HOT 1
- Provide a 'baseURL' option HOT 1
- userData domain level persistance not working HOT 1
- Publish/Subscribe across iframes HOT 4
- BUG: amplify.request on IE 9 not work HOT 2
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 amplify.