Skip to content

feat(platform-browser): allow lazy-loading HammerJS #23906

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 1 commit into from

Conversation

jelbourn
Copy link
Member

Open for discussion. I made the loader Promise-based instead of Observable for simplicity here, but can change it if folks feel strongly.

@jelbourn jelbourn added hotlist: components team Related to Angular CDK or Angular Material hotlist: google labels May 15, 2018
@jelbourn jelbourn requested review from mhevery and IgorMinar May 15, 2018 01:45
@mary-poppins
Copy link

You can preview 950f46f at https://pr23906-950f46f.ngbuilds.io/.

@Toxicable
Copy link

This might be a reasonable case for import()?

@jelbourn
Copy link
Member Author

@Toxicable the goal is to be agnostic to any particular loading implementation

@alfaproject
Copy link
Contributor

I’ve been telling people to stop using Promises because Observables are more powerful. I think it would be good to be consistent in the framework side too

@jelbourn jelbourn added the target: major This PR is targeted for the next major release label May 15, 2018
@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label May 15, 2018
@@ -58,6 +58,13 @@ const EVENT_NAMES = {
*/
export const HAMMER_GESTURE_CONFIG = new InjectionToken<HammerGestureConfig>('HammerGestureConfig');


/** Function that loads HammerJS, returning a promise that is resolved once HammerJs is loaded. */
export type HammerLoader = (() => Promise<void>) | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is | null correct here ?

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 believe so; null is an acceptable value to provide for the token

@Inject(HAMMER_GESTURE_CONFIG) private _config: HammerGestureConfig,
private console: Console) {
@Inject(HAMMER_GESTURE_CONFIG) private _config: HammerGestureConfig, private console: Console,
@Optional() @Inject(HAMMER_LOADER) private loader?: HammerLoader) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think | null should be here instead ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Per other comment: null is an acceptable value to provide for the token

export type HammerLoader = (() => Promise<void>) | null;

/** Injection token used to provide a {@link HammerLoader} to Angular. */
export const HAMMER_LOADER = new InjectionToken<HammerLoader>('HammerLoader');
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add public docs and @stablehere

Copy link
Contributor

Choose a reason for hiding this comment

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

@stable is no longer needed nor permitted. It is implied from a lack of @deprecated and @experimental tags.

mashhoodr pushed a commit to mashhoodr/angular that referenced this pull request May 28, 2018
@cyrilletuzi
Copy link
Contributor

@jelbourn Is there documentation somewhere to know how to use this feature? Thanks.

@jelbourn
Copy link
Member Author

No documentation yet, but it boils down to providing a function as HAMMER_LOADER, where the function returns a Promise that is resolved once Hammer is available on the page. The function can load Hammer however you want.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes hotlist: components team Related to Angular CDK or Angular Material hotlist: google target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants