New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Turn api.foo(auth, …)
into fully featured ApiConnection(auth).foo(…)
.
#4659
Comments
api.foo(auth, …)
into fully featured makeApi(auth).foo(…)
.api.foo(auth, …)
into fully featured ApiConnection(auth).foo(…)
.
See also chat discussion. |
Greg says:
|
What do we think about letting an |
Yeah, I agree. |
See discussion: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Maintaining.20.60edit_history.60.20on.20message-update.20events/near/1391009 Much of the plumbing added here can be removed with our plan to encapsulate the feature level in a new ApiConnection class; see zulip#4659 (comment)
We'll use this for a feature-level condition on FL 118 for edit_history. Most of this can be removed with our plan to encapsulate the feature level in a new ApiConnection class; see zulip#4659 (comment)
See discussion: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Maintaining.20.60edit_history.60.20on.20message-update.20events/near/1391009 Much of the plumbing added here can be removed with our plan to encapsulate the feature level in a new ApiConnection class; see zulip#4659 (comment)
We'll use this for a feature-level condition on FL 118 for edit_history. Most of this can be removed with our plan to encapsulate the feature level in a new ApiConnection class; see zulip#4659 (comment)
See discussion: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Maintaining.20.60edit_history.60.20on.20message-update.20events/near/1391009 Much of the plumbing added here can be removed with our plan to encapsulate the feature level in a new ApiConnection class; see zulip#4659 (comment)
This implementation plan is on the path to #4170. It will expose methods to cancel in-progress fetches, and for #4170 we'd just have to call those methods in the right places.
I've put together this plan from discussion with Greg in chat (@gnprice, please edit this plan liberally as needed! 🙂):
This is an area where I expect we'll be able to fruitfully write solid tests; see #4193 for examples of testing with Jest's fake timers.
We've never used React Native's
AbortController
polyfill (from facebook/react-native#24419, released in v0.60) before. There may be surprising differences from its standard, documented behavior. Anyway:Make the pure refactor to replace
api.foo(auth, …)
withApiConnection(auth).foo(…)
.Have
ApiConnection
implement a cache, keyed by the email and realm (i.e. the identity, as inidentityOfAuth: Auth => Identity
) fromauth
. We wantApiConnection
to return the same object for the same identity, and a different object for a different identity.Allow canceling all in-progress fetches at once:
ApiConnection(auth)
is called, have it create an empty array or set called something likeabortControllers
.abortControllers
will be maintained so that it always comprises one item per in-progress request.fetch
, create a newAbortController
object and pass itsAbortSignal
in thefetch
call (notefetch
'ssignal
param). Add theAbortController
object toabortControllers
.AbortController
object fromabortControllers
because only in-progress fetches should be there.ApiConnection(auth)
grow an.abortAll
method. That method should call.abort()
on all items inabortControllers
. That'll cancel all in-progress fetches.Allow canceling individual fetches:
ApiConnection(auth).foo
take an optionalsignal: AbortSignal
, probably in a params object with its other params.signal
is passed, callsignal.addEventListener('abort', …)
, with a handler that calls.abort()
on this request'sAbortController
inabortControllers
. (This is less direct than just passing the suppliedsignal
to thefetch
, but that'd make it tricky to also have.abortAll
(see above) because a singlefetch
call takes just onesignal
and so can't directly listen to multipleAbortController.abort()
s at once.)The text was updated successfully, but these errors were encountered: