8000 feat(cdk): add rxScheduleTask function by Karnaukhov-kh · Pull Request #1344 · rx-angular/rx-angular · GitHub
[go: up one dir, main page]

Skip to content

feat(cdk): add rxScheduleTask function #1344

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

Closed
wants to merge 9 commits into from

Conversation

Karnaukhov-kh
Copy link
Member

Introduces rxScheduleTask function to schedule tasks with our scheduler.

@nx-cloud
Copy link
nx-cloud bot commented May 18, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4aa53ee. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 4 targets

Sent with 💌 from NxCloud.

@github-actions github-actions bot added 📖 Docs API Documentation in the source code 🛠️ CDK CDK related labels May 18, 2022
Copy link
Member
@hoebbelsB hoebbelsB left a comment

Choose a reason for hiding this comment

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

hi @Karnaukhov-kh very nice PR, i like the idea a lot! Left some thoughts in the comments

Comment on lines 31 to 47
export const rxScheduleTask = (
work: (...args: any[]) => void,
strategy: keyof StrategiesPriorityRecord = 'normal',
options?: {
delay?: number;
ngZone?: NgZone;
}
) => {
const task = scheduleCallback(
strategiesPrio[strategy],
() => work(),
options
);
return () => {
cancelCallback(task);
};
};
Copy link
Member

Choose a reason for hiding this comment

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

why don't we provide an observable version of this standalone function as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't scheduleOnQueue already an operator that uses it, but with coalescing?

*/
export const rxScheduleTask = (
work: (...args: any[]) => void,
strategy: keyof StrategiesPriorityRecord = 'normal',
Copy link
Member

Choose a reason for hiding this comment

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

How would a user use the function with a custom strategy? the typing wouldn't allow it currently. Or am I missing something?

Copy link
Member Author
@Karnaukhov-kh Karnaukhov-kh May 28, 2022

Choose a reason for hiding this comment

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

I guess we should not use custom strategy here, because only thing we need from strategy is priority. And scheduler not working with custom priority levels.

That's why we need this ⬇️, to provide users familiar API instead of PriorityLevel enum.

const strategiesPrio: StrategiesPriorityRecord = {
  immediate: PriorityLevel.ImmediatePriority,
  userBlocking: PriorityLevel.UserBlockingPriority,
  normal: PriorityLevel.NormalPriority,
  low: PriorityLevel.LowPriority,
  idle: PriorityLevel.IdlePriority,
};

Copy link
Member
@edbzn edbzn left a comment

Choose a reason for hiding this comment

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

Nice work, I would add some unit tests to see if the scheduleCallback is correctly called. I think that render-strategies is not the right place to expose that fn, but I can't figure out a better place.

@Karnaukhov-kh
Copy link
Member Author

Thank you for feedback @hoebbelsB @edbzn, I'll answer and apply changes soon :).

Comment on lines +33 to +52
export const rxScheduleTask = (
work: (...args: any[]) => void,
8000 options?: {
strategy?: keyof StrategiesPriorityRecord;
delay?: number;
ngZone?: NgZone;
}
) => {
const task = scheduleCallback(
strategiesPrio[options?.strategy || defaultStrategy],
() => work(),
{
delay: options?.delay,
ngZone: options?.ngZone,
}
);
return () => {
cancelCallback(task);
};
};
Copy link
Member

Choose a reason for hiding this comment

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

What about the following syntax to initialize options?

Suggested change
export const rxScheduleTask = (
work: (...args: any[]) => void,
options?: {
strategy?: keyof StrategiesPriorityRecord;
delay?: number;
ngZone?: NgZone;
}
) => {
const task = scheduleCallback(
strategiesPrio[options?.strategy || defaultStrategy],
() => work(),
{
delay: options?.delay,
ngZone: options?.ngZone,
}
);
return () => {
cancelCallback(task);
};
};
export const rxScheduleTask = (
work: (...args: any[]) => void,
{
strategy = defaultStrategy,
delay,
ngZone,
}: {
strategy?: keyof StrategiesPriorityRecord;
delay?: number;
ngZone?: NgZone;
} = {}
) => {
const task = scheduleCallback(strategiesPrio[strategy], () => work(), {
delay,
ngZone,
});
return () => {
cancelCallback(task);
};
};

@codecov
Copy link
codecov bot commented Sep 13, 2022

Codecov Report

Merging #1344 (4aa53ee) into main (a63e01a) will increase coverage by 1.30%.
The diff coverage is 41.66%.

@@            Coverage Diff             @@
##             main    #1344      +/-   ##
==========================================
+ Coverage   73.61%   74.92%   +1.30%     
==========================================
  Files         145      108      -37     
  Lines        2858     2213     -645     
  Branches      514      378     -136     
==========================================
- Hits         2104     1658     -446     
+ Misses        627      446     -181     
+ Partials      127      109      -18     
Impacted Files Coverage Δ
.../cdk/render-strategies/src/lib/rx-schedule-task.ts 36.36% <36.36%> (ø)
libs/cdk/render-strategies/src/index.ts 100.00% <100.00%> (ø)
...ions/src/lib/operators/distinctUntilSomeChanged.ts
libs/state/selections/src/lib/operators/select.ts
libs/state/selections/src/lib/utils/guards.ts
libs/state/actions/src/lib/transforms.ts
.../deprecated/transformation-helpers/array/upsert.ts
.../deprecated/transformation-helpers/object/patch.ts
libs/state/actions/src/lib/proxy.ts
libs/state/selections/src/lib/operators/index.ts
... and 30 more

@Karnaukhov-kh
Copy link
Member Author

Closing in favor of #1633

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🛠️ CDK CDK related 📖 Docs API Documentation in the source code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0