-
-
Notifications
You must be signed in to change notification settings - Fork 650
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
updateExistingStream: Reduce api calls on changing stream details. #3224
Conversation
src/api/streams/updateStream.js
Outdated
}; | ||
|
||
export default (auth: Auth, id: number, newValues: ParamsType): Promise<ApiResponse> => | ||
apiPatch(auth, `streams/${id}`, res => res, { ...newValues }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to spread the values?
```{ ...newValues }`` vs just newValues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried with newValues
, then flow is giving error.
Cannot call apiPatch with newValues bound to params because:
• string [1] is incompatible with boolean [2] in property description.
• string [1] is incompatible with number [3] in property description.
• boolean [4] is incompatible with string [5] in property is_private.
• boolean [4] is incompatible with number [3] in property is_private.
• string [6] is incompatible with boolean [2] in property new_name.
• string [6] is incompatible with number [3] in property new_name.
src/api/streams/updateStream.js
[6] 6│ new_name?: string,
[1] 7│ description?: string,
[4] 8│ is_private?: boolean,
9│ };
10│
11│ export default (auth: Auth, id: number, newValues: ParamsType): Promise<ApiResponse> =>
12│ apiPatch(auth, `streams/${id}`, res => res, newValues);
13│
src/utils/url.js
[5][2][3] 16│ export type UrlParams = { [string]: string | boolean | number };
Found 6 errors
In toggleMobilePushSettings
also we are creating new object.
export default async ({
auth,
opp,
value,
}: {
auth: Auth,
opp: string,
value: boolean,
}): Promise<ApiResponse> =>
apiPatch(auth, 'settings/notifications', res => res, {
...getRequestBody(opp, value),
});
So I thought of doing same 😅
src/api/streams/updateStream.js
Outdated
export type ParamsType = { | ||
new_name?: string, | ||
description?: string, | ||
is_private?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an exhaustive list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup! stream have limited properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParamsType
does not sound like concrete or a good name.
First, we don't name types *Type
:)
Also, Param
? It is a parameter/argument to a function but you can do better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any name you want to suggest? :)
ApiBody
, ApiParameters
??
src/streams/streamsActions.js
Outdated
@@ -26,21 +27,20 @@ export const updateExistingStream = ( | |||
initialValues: Object, | |||
newValues: Object, | |||
) => async (dispatch: Dispatch, getState: GetState) => { | |||
const apiParams: UpdateStreamApiParamsType = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a candidate for a utility function.
The chances are that we will add more fields and we will need this logic in other places.
What if you do create a currentValues
object with the values needed.
Then we can diff it against the current version (via a utility function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we need to do some refactors, like
- currently we have
name
key (for stream name) ininitialValues
andnewValues
But at the time of sending parameters to API, we want keynew_name
, so again a if/else will be required.
Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest you do an object diffing function and then pass the resulting object (if it is not empty!) to this new function:
https://github.com/zulip/zulip-mobile/blob/master/src/api/apiFetch.js#L14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(#3140 is blocked on this)
3f43ccb
to
16ef27d
Compare
Before inidividual api calls were made for each stream property which is changed. But on server, this api is capable of handeling multiple propery at a time. So just call api once with all the properties which are changed. Fixes: zulip#3222
16ef27d
to
fed1791
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@borisyankov Updated 👍
Before inidividual api calls were made for each stream property which
is changed. But on server, this api is capable of handeling multiple
propery at a time. So just call api once with all the properties which
are changed.
Fixes: #3222