-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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(layout-direction): a service to accompany the Dir directive #2286
Conversation
@@ -1,6 +1,6 @@ | |||
import {NgModule, ModuleWithProviders} from '@angular/core'; | |||
import {MdLineModule} from './line/line'; | |||
import {RtlModule} from './rtl/dir'; | |||
import {RtlModule} from './rtl/index'; |
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.
You shouldn't need index
in there
|
||
constructor(private _appRef: ApplicationRef) {} | ||
|
||
getActiveDirection(injector: Injector): Promise<LayoutDirection> { |
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.
Needs JsDoc description (here and for other method)
}) | ||
.then(rootComponent => { | ||
return this._getParentDirection(rootComponent); | ||
}); |
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.
return Promise.resolve(null)
.then(() => this._getRootElement(injector))
.then(rootComponent => this._getParentDirection(rootComponent));
Also add comment explaining why the Promise.resolve
is necessary
|
||
for (let i = 0; i < this._appRef.componentTypes.length; i++) { | ||
if (injector.get(this._appRef.componentTypes[i])) { | ||
rootComponent = this._appRef.components[i].location; |
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.
You can just return
directly here
|
||
@Injectable() | ||
export class ActiveLayoutDirection { | ||
dirChange = new EventEmitter<void>(); |
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 do someting like
dirChange = Observable.of([])
With a comment explaining that this won't ever fire anything
} from '@angular/core'; | ||
|
||
import {LayoutDirection} from './dir'; | ||
import {EventEmitter} from '@angular/common/src/facade/async'; |
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 is unnecessary since it will be changed to an Observable
, but FYI never deep import from anything in @angular/xxx
. This would normally be
import {EventEmitter} from '@angular/core';
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.
Webstorm auto import 😅
return rootComponent.nativeElement; | ||
} | ||
|
||
_getParentDirection(element: HTMLElement): string { |
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.
_getClosestAncestorDirValue
constructor( | ||
private _renderer: Renderer, | ||
private _element: ElementRef, | ||
@Optional() private _dir: Dir) {} | ||
@Optional() _activeLayoutDirection: ActiveLayoutDirection, | ||
@Optional() _injector: Injector) { |
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.
Injector
doesn't have to be @Optional
. You can always inject an Injector
.
import {EventEmitter} from '@angular/common/src/facade/async'; | ||
|
||
@Injectable() | ||
export class ActiveLayoutDirection { |
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.
Rename this class to something like GlobalDirAccessor
and then add another class called ActiveLayoutDirection
that just looks like
export class ActiveLayoutDirection {
dirChange: Observable<void>;
getActiveDirection(injector: Injector): Promise<LayoutDirection> { return null; }
}
The both Dir
and GlobalDirAccessor
will have implements ActiveLayoutDirection
(TypeScript lets you implement
a class just like an interface. Keeping it as a class lets us use it as an injection token).
fd9b073
to
0e77ce7
Compare
0e77ce7
to
33decab
Compare
- Finds the application root element and traverses upwards and looking for dir attribute - If Dir directive is available throughout the application it will be injected instead the activeLayoutDirection service fixes angular#1719
33decab
to
d2e7d3e
Compare
@EladBezalel was this ready for another round of review? |
nope 😅 |
A better solution was suggested on #3600 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
fixes #1719