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

feat(core): implement onWatch #165

Merged
merged 2 commits into from
Feb 10, 2022
Merged

feat(core): implement onWatch #165

merged 2 commits into from
Feb 10, 2022

Conversation

mhevery
Copy link
Contributor

@mhevery mhevery commented Feb 1, 2022

Closes #63

@mhevery mhevery force-pushed the pr-on-watch branch 3 times, most recently from fca71ed to a75b709 Compare February 9, 2022 03:53
Copy link
Contributor

@manucorporat manucorporat left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -129,6 +129,11 @@ export interface JSXNode<T = any> {
// @public
export function notifyRender(hostElement: Element): Promise<void>;

// @public
export interface Observer {
<T extends {}>(obj: T): T;
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be interesting to make this more strongly typed, can we observe any kind of objects? I have an idea of how to achieve this, we can develop on a call.

anyway, good to merge for now!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's get a discussion going.

@@ -165,6 +170,12 @@ export const onUnmount$: (first: () => void) => void;
// @public
export function onUnmount(unmountFn: QRL<() => void>): void;

// @public
export const onWatch$: (first: (obs: Observer) => unknown | (() => void)) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

if we can return a promise, then we should use ValueOrPromise

Suggested change
export const onWatch$: (first: (obs: Observer) => unknown | (() => void)) => void;
export const onWatch$: (first: (obs: Observer) => ValueOrPromise<unknown | (() => void)) => void>;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should allow a promise here. Because the whole point of the return function is to have a cleanup in case we have to call it again. If it is a promise then the cleanup function may show up way too late.

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha! makes sense

@gitguardian
Copy link

gitguardian bot commented Feb 10, 2022

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.

@mhevery mhevery enabled auto-merge (squash) February 10, 2022 17:14
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.

Design qEffect API
2 participants