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(platform-browser): allow lazy-loading HammerJS #23906

Closed
wants to merge 1 commit into
base: master
from

Conversation

@jelbourn
Member

jelbourn commented May 15, 2018

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

@mary-poppins

This comment has been minimized.

mary-poppins commented May 15, 2018

@Toxicable

This comment has been minimized.

Contributor

Toxicable commented May 15, 2018

This might be a reasonable case for import()?

@jelbourn

This comment has been minimized.

Member

jelbourn commented May 15, 2018

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

@alfaproject

This comment has been minimized.

Contributor

alfaproject commented May 15, 2018

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

@@ -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;

This comment has been minimized.

@vicb

vicb May 15, 2018

Contributor

Is | null correct here ?

This comment has been minimized.

@jelbourn

jelbourn May 15, 2018

Member

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) {

This comment has been minimized.

@vicb

vicb May 15, 2018

Contributor

I think | null should be here instead ?

This comment has been minimized.

@jelbourn

jelbourn May 15, 2018

Member

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');

This comment has been minimized.

@mhevery

mhevery May 16, 2018

Member

You need to add public docs and @stablehere

This comment has been minimized.

@petebacondarwin

petebacondarwin May 23, 2018

Member

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

mashhoodr added a commit to mashhoodr/angular that referenced this pull request May 28, 2018

@cyrilletuzi

This comment has been minimized.

Contributor

cyrilletuzi commented Jul 26, 2018

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

@jelbourn

This comment has been minimized.

Member

jelbourn commented Jul 26, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment