-
Notifications
You must be signed in to change notification settings - Fork 395
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
Conversation
webapp/packages/core-data-context/src/DataContext/DataContext.ts
Outdated
Show resolved
Hide resolved
version++; | ||
this.map.set(context, value); | ||
this.versions.set(context, version); | ||
data.set(id, value); |
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.
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);
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.
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
webapp/packages/core-data-context/src/DataContext/DataContext.ts
Outdated
Show resolved
Hide resolved
export function useDataContextLink(context: IDataContext | undefined, update: (context: IDataContext, id: string) => void): void { | ||
const [id] = useState(() => uuid()); | ||
|
||
useLayoutEffect(() => { |
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.
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).
webapp/packages/core-data-context/src/DataContext/useDataContextLink.ts
Outdated
Show resolved
Hide resolved
this.store.clear(); | ||
} | ||
|
||
private internalGet<T>(context: DataContextGetter<T>): T | typeof NOT_FOUND { |
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.
_get ?
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.
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'); |
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.
Looks strange. Is there a way to avoid this?
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 don't know any way to keep the generic type without using it in the object
} | ||
}); | ||
|
||
useLayoutEffect( |
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.
Please fix lint errors
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.
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); |
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.
Seems like getNodes is always defined now
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.
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); |
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.
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); |
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.
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; |
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.
Seems like this pattern is not stable as the developer can easily pass authInfoService.userInfo directly to the callback fn without reassigning this first
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.
fixed
No description provided.