Skip to content
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

Refactor cb-4018 data context api #2708

Merged
merged 13 commits into from
Jun 18, 2024
Merged

Refactor cb-4018 data context api #2708

merged 13 commits into from
Jun 18, 2024

Conversation

Wroud
Copy link
Member

@Wroud Wroud commented Jun 13, 2024

No description provided.

@Wroud Wroud requested a review from devnaumov June 13, 2024 15:35
@Wroud Wroud self-assigned this Jun 13, 2024
@Wroud Wroud requested a review from sergeyteleshev June 13, 2024 15:35
version++;
this.map.set(context, value);
this.versions.set(context, version);
data.set(id, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case where data was already defined it misses an if statement above where you set new context to the shallow observable store

this means that mobx wont be triggered if value changed in data, right? should we just move this line to the end of the function?

this.store.set(context, data);

Copy link
Member Author

@Wroud Wroud Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, here is all fine, to access data mobx will track both Maps and when we change value all subscribers to that value will be notified

export function useDataContextLink(context: IDataContext | undefined, update: (context: IDataContext, id: string) => void): void {
const [id] = useState(() => uuid());

useLayoutEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this one bad boy. I tried to remove both useLayoutEffects and at first glance the app works fine (did not invest many time to explore the whole app).

this.store.clear();
}

private internalGet<T>(context: DataContextGetter<T>): T | typeof NOT_FOUND {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't like this prefixes

@@ -5,9 +5,11 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import type { IDataContextProvider } from './IDataContextProvider';

const typescriptTypeLink = Symbol('typescript type link');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks strange. Is there a way to avoid this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know any way to keep the generic type without using it in the object

}
});

useLayoutEffect(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix lint errors

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const node = context.tryGet(DATA_CONTEXT_NAV_NODE);
const getNodes = context.tryGet(DATA_CONTEXT_NAV_NODES);
const node = context.get(DATA_CONTEXT_NAV_NODE);
const getNodes = context.get(DATA_CONTEXT_NAV_NODES);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like getNodes is always defined now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type of get changed from T to T | undefined and equal to type of tryGet. so it's basically tryGet replaced get

@@ -48,7 +48,7 @@ export class CreateUserBootstrap extends Bootstrap {
},
isDisabled: (context, action) => {
if (action === ACTION_CREATE) {
const administrationItemRoute = context.tryGet(DATA_CONTEXT_ADMINISTRATION_ITEM_ROUTE);
const administrationItemRoute = context.get(DATA_CONTEXT_ADMINISTRATION_ITEM_ROUTE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

administrationItemRoute is defined now, not need for the ?.

@@ -68,13 +68,13 @@ export class ConnectionMenuBootstrap extends Bootstrap {
return false;
}

const connection = context.tryGet(DATA_CONTEXT_CONNECTION);
const connection = context.get(DATA_CONTEXT_CONNECTION);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check ?. here and all the way down where you change tryGet -> get

@@ -21,16 +22,19 @@ export const UserMenu = observer(function UserMenu() {
const styles = useS(style);
const authInfoService = useService(AuthInfoService);
const menu = useMenu({ menu: MENU_USER_PROFILE });
const userInfo = authInfoService.userInfo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this pattern is not stable as the developer can easily pass authInfoService.userInfo directly to the callback fn without reassigning this first

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@sergeyteleshev sergeyteleshev self-requested a review June 14, 2024 14:35
@devnaumov devnaumov self-requested a review June 14, 2024 14:46
@Wroud Wroud merged commit 9a471be into devel Jun 18, 2024
7 checks passed
@Wroud Wroud deleted the refactor/cb-4018/data-context branch June 18, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants