-
Notifications
You must be signed in to change notification settings - Fork 772
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
fix(lib, media-query): support angular/universal #353
Conversation
c2e03f2
to
4425a1a
Compare
constructor(ref: ElementRef) { | ||
const getMouseEventPosition = (event: MouseEvent) => ({x: event.movementX, y: event.movementY}); | ||
|
||
const mouseup$ = Observable.fromEvent(document, 'mouseup'); |
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 think you have to inject 'DOCUMENT' from 'platform-browser'.
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.
@ardatan - true. I think even better is to use ref.nativeElement.ownerDocument
. Your thoughts ?
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.
@ThomasBurleson I am not sure if platform-server
has ownerDocument
property implementation.
4425a1a
to
f5cf9e9
Compare
@ardatan - BTW, even with injection or 11:14:25] 'prerender' errored after 611 ms
[11:14:25] Error: ERROR TypeError: Invalid event target
at Function.FromEventObservable.setupSubscription (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/observable/FromEventObservable.js:113:19)
at FromEventObservable._subscribe (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/observable/FromEventObservable.js:135:29)
at FromEventObservable.Observable._trySubscribe (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/Observable.js:171:25)
at FromEventObservable.Observable.subscribe (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/Observable.js:159:65)
at MapOperator.call (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/operator/map.js:54:23)
at Observable.subscribe (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/Observable.js:156:22)
at SwitchMapOperator.call (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/operator/switchMap.js:67:23)
at Observable.subscribe (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/rxjs/Observable.js:156:22)
at SplitDirective.ngAfterContentInit (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/dist/packages/universal-app/app/splitter/split.directive.js:18:41)
at callProviderLifecycles (/Users/thomasburleson/Documents/projects/Google/projects/angular-layouts/node_modules/@angular/core/bundles/core.umd.js:11206:18) Any ideas ? |
in 'split-handle-directive.ts', I think it had better to take events into Observable by using HostListener. I changed like that, and ran ci:prerender. It was successful. You can try. import {Directive, ElementRef, Output, Inject, EventEmitter, HostListener} from '@angular/core';
import {DOCUMENT} from '@angular/platform-browser';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';
import 'rxjs/add/operator/takeUntil';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/map';
@Directive({
selector: '[ngxSplitHandle]',
host: {
class: 'ngx-split-handle',
title: 'Drag to resize'
}
})
export class SplitHandleDirective {
@Output() drag: Observable<{ x: number, y: number }>;
mousedown$ = new EventEmitter();
constructor(private ref: ElementRef, @Inject(DOCUMENT) private document: any) { }
ngAfterViewInit() {
const getMouseEventPosition = (event: MouseEvent) => ({ x: event.movementX, y: event.movementY });
const mouseup$ = Observable.fromEvent(this.document, 'mouseup');
const mousemove$ = Observable.fromEvent(this.document, 'mousemove')
.map(getMouseEventPosition);
this.drag = this.mousedown$.switchMap(_ => mousemove$.takeUntil(mouseup$));
}
@HostListener('mousedown', ['$event']) onMouseDown(event) {
this.mousedown$.next(event);
}
} |
d3acdbe
to
1f62f0c
Compare
@ardatan - fixed it. Need to use |
@ThomasBurleson it is ready to merge? |
@ardatan - we have a rigorous merge process that includes tests with many applications internal to Google. This will be marked as |
@ThomasBurleson I understand. Thank you for explanation.
|
@ThomasBurleson I have an idea about pre-rendered flex-layout pages. Now when we are using flex-layout with universal, it only applies default styles than changes by current screen. What do you think? |
src/lib/flexbox/api/base.ts
Outdated
let findDirection = (styles) => directionKeys.reduce((direction, key) => { | ||
return direction || styles[key]; | ||
}, null); | ||
let immediateValue = getDom().getStyle(target, 'flex-direction'); |
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.
this logic appears twice, move to helper function?
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.
@@ -19,13 +20,14 @@ export class SplitHandleDirective { | |||
|
|||
constructor(ref: ElementRef) { | |||
const getMouseEventPosition = (event: MouseEvent) => ({x: event.movementX, y: event.movementY}); | |||
const document = ref.nativeElement.ownerDocument; |
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 see elsewhere you are doing @Inject(DOCUMENT)
why not same here?
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 will sync the solutions to be the same. Thx.
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.
src/lib/media-query/match-media.ts
Outdated
let canListen = !!(<any>window).matchMedia('all').addListener; | ||
return canListen ? (<any>window).matchMedia(query) : <MediaQueryList>{ | ||
protected _buildMQL(query: string): MediaQueryList { | ||
let canListen = (typeof matchMedia != 'undefined'); |
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.
can just do canListen = !!matchMedia
or not even and just do:
if (matchMedia) {
...
}
return matchMedia ? ...;
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 will use the angular Universal isBrowser()
solution.
outline: none; | ||
-webkit-user-select: none; | ||
user-select: none; | ||
z-index: 9999; |
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.
does the z-index need to be so high?
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 just chose an arbitrary large 100.
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.
top: 50%; | ||
left: -2px; | ||
transform: translateX(-50%) rotate(270deg); | ||
cursor: col-resize;; |
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.
double ;
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.
534f14c
to
56a53f6
Compare
@mmalerba - all comments fixed. Thank you sir. |
56a53f6
to
7311f99
Compare
8f5330e
to
f8f56f3
Compare
With last head build, Universal still does not work with Flex Layout, got these errors :
Does not crash the server, but stop rendering all the rest of the page. |
@cyrilletuzi - we need your help to reproduce this issue. Do you have a small demo that we can test locally to produce the same error ? Also please create a new issue for this... or add extra information to issue #354. |
Sorry, it was just a package synchronisation issue (I updated my app flex layout package but not the server one...), all is OK now and I can close the reflect issue. Is it possible to release a beta.9 for this ? I suppose if it's not still here yet it's because there are other things coming, but as it's a beta release it is not critical to miss some other points and would be better than rely on nightly builds. |
@cyrilletuzi - thx for the follow-up and confirmation/closure of your issue. We hope to release Beta.9 this week. |
great OSS work guys. |
Use getDom() for platform-server/universal fixes.
Now gets document object from platform-browser by DI instead of global.
Fixes #187, #354. Closes #346.