Skip to content

Commit

Permalink
feat(component-loader): added resolve method
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin committed Dec 15, 2016
1 parent b25f8d7 commit ea1de3c
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 37 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"flow.changelog": "conventional-changelog -i CHANGELOG.md -s -p angular -v",
"flow.github-release": "conventional-github-releaser -p angular",
"build": "ngm build -p src",
"build.watch": "ngm build -p src --watch --skip-bundles",
"start": "ng serve --aot",
"generate-bs4": "node scripts/generate-bs4.js",
"pretest": "run-s lint build link",
Expand Down Expand Up @@ -90,7 +91,7 @@
"lodash": "4.17.2",
"markdown-loader": "github:valorkin/markdown-loader",
"marked": "0.3.6",
"ngm-cli": "0.3.4",
"ngm-cli": "^0.3.6",
"npm-run-all": "3.1.2",
"pre-commit": "1.2.1",
"protractor": "4.0.13",
Expand Down
12 changes: 10 additions & 2 deletions src/component-loader/component-loader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// todo: add global positioning configuration?
import {
NgZone, ViewContainerRef, ComponentFactoryResolver, Injector, Renderer,
ElementRef, ComponentRef, ComponentFactory, Type, TemplateRef, EventEmitter
ElementRef, ComponentRef, ComponentFactory, Type, TemplateRef, EventEmitter,
Provider, ReflectiveInjector
} from '@angular/core';
import { ContentRef } from './content-ref.class';
import { PositioningService, PositioningOptions } from '../positioning';
Expand All @@ -26,6 +27,7 @@ export class ComponentLoader<T> {
public instance: T;
public _componentRef: ComponentRef<T>;

private _providers: Provider[] = [];
private _componentFactory: ComponentFactory<T>;
private _elementRef: ElementRef;
private _zoneSubscription: any;
Expand Down Expand Up @@ -104,14 +106,20 @@ export class ComponentLoader<T> {
return this;
}

public provide(provider: Provider): ComponentLoader<T> {
this._providers.push(provider);
return this;
}

public show(content?: string | TemplateRef<any>, mixin?: any): ComponentRef<T> {
this._subscribePositioning();

if (!this._componentRef) {
this.onBeforeShow.emit();
this._contentRef = this._getContentRef(content);
const injector = ReflectiveInjector.resolveAndCreate(this._providers, this._injector);
this._componentRef = this._viewContainerRef
.createComponent(this._componentFactory, 0, this._injector, this._contentRef.nodes);
.createComponent(this._componentFactory, 0, injector, this._contentRef.nodes);
this.instance = this._componentRef.instance;

Object.assign(this._componentRef.instance, mixin || {});
Expand Down
7 changes: 6 additions & 1 deletion src/popover/popover-container.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChangeDetectionStrategy, Input, Component } from '@angular/core';
import { PopoverConfig } from './popover-config';

@Component({
selector: 'popover-container',
Expand All @@ -11,6 +12,10 @@ import { ChangeDetectionStrategy, Input, Component } from '@angular/core';
`
})
export class PopoverContainerComponent {
@Input() public placement: string = 'top';
@Input() public placement: string;
@Input() public title: string;

public constructor(config: PopoverConfig) {
Object.assign(this, config);
}
}
3 changes: 2 additions & 1 deletion src/popover/popover.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export class PopoverDirective implements OnInit, OnDestroy {
_config: PopoverConfig,
cis: ComponentLoaderFactory) {
this._popover = cis
.createLoader<PopoverContainerComponent>(_elementRef, _viewContainerRef, _renderer);
.createLoader<PopoverContainerComponent>(_elementRef, _viewContainerRef, _renderer)
.provide({provide: PopoverConfig, useValue: _config});
Object.assign(this, _config);
this.onShown = this._popover.onShown;
this.onHidden = this._popover.onHidden;
Expand Down
13 changes: 10 additions & 3 deletions src/tooltip/tooltip-container.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import {
AfterViewInit, ChangeDetectorRef, Component, ElementRef, TemplateRef,
ChangeDetectionStrategy
AfterViewInit, Component, ChangeDetectionStrategy, Inject
} from '@angular/core';
import { TooltipConfig } from './tooltip.config';

@Component({
selector: 'bs-tooltip-container',
changeDetection: ChangeDetectionStrategy.OnPush,
// tslint:disable-next-line
host: {'[class]': '"tooltip in tooltip-" + placement + " " + placement', role: 'tooltip'},
host: {
'[class]': '"tooltip in tooltip-" + placement + " " + placement',
role: 'tooltip'
},
template: `
<div class="tooltip-arrow"></div>
<div class="tooltip-inner"><ng-content></ng-content></div>
Expand Down Expand Up @@ -38,6 +41,10 @@ export class TooltipContainerComponent implements AfterViewInit {
public popupClass: string;
public animation: boolean;

public constructor(config: TooltipConfig) {
Object.assign(this, config);
}

public ngAfterViewInit(): void {
this.classMap = {in: false, fade: false};
this.classMap[this.placement] = true;
Expand Down
44 changes: 30 additions & 14 deletions src/tooltip/tooltip.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class TooltipDirective implements OnInit, OnDestroy {
/**
* Allows to disable tooltip
*/
@Input() public isDisabled:boolean;
@Input() public isDisabled: boolean;

/**
* Emits an event when the tooltip is shown
Expand All @@ -60,54 +60,67 @@ export class TooltipDirective implements OnInit, OnDestroy {

/* tslint:disable */
/** @deprecated */
@Input('tooltipHtml') public set htmlContent(value: string | TemplateRef<any>){
@Input('tooltipHtml')
public set htmlContent(value: string | TemplateRef<any>) {
console.warn('tooltipHtml was deprecated, please use `tooltip` instead');
this.tooltip = value;
}

/** @deprecated */
@Input('tooltipPlacement') public set _placement(value: string){
@Input('tooltipPlacement')
public set _placement(value: string) {
console.warn('tooltipPlacement was deprecated, please use `placement` instead');
this.placement = value;
}

/** @deprecated */
@Input('tooltipIsOpen') public set _isOpen(value:boolean) {
@Input('tooltipIsOpen')
public set _isOpen(value: boolean) {
console.warn('tooltipIsOpen was deprecated, please use `isOpen` instead');
this.isOpen = value;
}
public get _isOpen():boolean {

public get _isOpen(): boolean {
console.warn('tooltipIsOpen was deprecated, please use `isOpen` instead');
return this.isOpen;
}

/** @deprecated */
@Input('tooltipEnable') public set _enable(value: boolean){
@Input('tooltipEnable')
public set _enable(value: boolean) {
console.warn('tooltipEnable was deprecated, please use `isDisabled` instead');
this.isDisabled = value === true;
}
public get _enable(): boolean{

public get _enable(): boolean {
console.warn('tooltipEnable was deprecated, please use `isDisabled` instead');
return this.isDisabled === true;
}

/** @deprecated */
@Input('tooltipAppendToBody') public set _appendToBody(value: boolean) {
@Input('tooltipAppendToBody')
public set _appendToBody(value: boolean) {
console.warn('tooltipAppendToBody was deprecated, please use `container="body"` instead');
this.container = value ? 'body' : this.container;
}

public get _appendToBody():boolean {
public get _appendToBody(): boolean {
console.warn('tooltipAppendToBody was deprecated, please use `container="body"` instead');
return this.container === 'body';
}

/** @deprecated */
@Input('tooltipAnimation') public _animation: boolean = true;

/** @deprecated */
@Input('tooltipClass') public set _popupClass(value: string){
@Input('tooltipClass')
public set _popupClass(value: string) {
console.warn('tooltipClass deprecated');
}

/** @deprecated */
@Input('tooltipContext') public set _tooltipContext(value: any){
@Input('tooltipContext')
public set _tooltipContext(value: any) {
console.warn('tooltipContext deprecated');
}

Expand All @@ -117,15 +130,17 @@ export class TooltipDirective implements OnInit, OnDestroy {
@Input('tooltipFadeDuration') public _fadeDuration: number = 150;

/** @deprecated */
@Input('tooltipTrigger') public get _tooltipTrigger():string|Array<string>{
@Input('tooltipTrigger')
public get _tooltipTrigger(): string|Array<string> {
console.warn('tooltipTrigger was deprecated, please use `triggers` instead');
return this.triggers;
};

public set _tooltipTrigger(value:string|Array<string>){
public set _tooltipTrigger(value: string|Array<string>) {
console.warn('tooltipTrigger was deprecated, please use `triggers` instead');
this.triggers = (value || '').toString();
};

/* tslint:enable */

@Output() public tooltipStateChanged: EventEmitter<boolean> = new EventEmitter<boolean>();
Expand All @@ -141,7 +156,8 @@ export class TooltipDirective implements OnInit, OnDestroy {
cis: ComponentLoaderFactory,
config: TooltipConfig) {
this._tooltip = cis
.createLoader<TooltipContainerComponent>(_elementRef, _viewContainerRef, _renderer);
.createLoader<TooltipContainerComponent>(_elementRef, _viewContainerRef, _renderer)
.provide({provide: TooltipConfig, useValue: config});

Object.assign(this, config);
this.onShown = this._tooltip.onShown;
Expand Down
34 changes: 19 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@
version "2.0.29"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-2.0.29.tgz#5002e14f75e2d71e564281df0431c8c1b4a2a36a"

"@types/node@*", "@types/[email protected]":
version "6.0.49"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.49.tgz#c644f7305e0d64bd797c939af833f22d150e1d33"

"@types/[email protected]", "@types/node@^6.0.46":
"@types/node@*", "@types/[email protected]", "@types/node@^6.0.46":
version "6.0.48"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.48.tgz#86ccc15f66b73cbbc5eb3483398936c585122b3c"

"@types/[email protected]":
version "6.0.49"
resolved "https://registry.yarnpkg.com/@types/node/-/node-6.0.49.tgz#c644f7305e0d64bd797c939af833f22d150e1d33"

"@types/q@^0.0.32":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@types/q/-/q-0.0.32.tgz#bd284e57c84f1325da702babfc82a5328190c0c5"
Expand Down Expand Up @@ -609,7 +609,7 @@ [email protected]:
dependencies:
lodash "^4.3.0"

[email protected]:
[email protected], async@^2.0.0, async@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/async/-/async-2.0.1.tgz#b709cc0280a9c36f09f4536be823c838a9049e25"
dependencies:
Expand All @@ -619,7 +619,7 @@ async@^0.9.0, async@~0.9.0:
version "0.9.2"
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"

async@^2.0.0, async@^2.0.1, async@^2.1.2:
async@^2.1.2:
version "2.1.4"
resolved "https://registry.yarnpkg.com/async/-/async-2.1.4.tgz#2d2160c7788032e4dd6cbe2502f1f9a2c8f6cde4"
dependencies:
Expand Down Expand Up @@ -4994,14 +4994,14 @@ nested-error-stacks@^2.0.0:
dependencies:
inherits "~2.0.1"

[email protected].4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/ngm-cli/-/ngm-cli-0.3.4.tgz#adcbedcc84a444b246aaa9cf34672403b7174a14"
ngm-cli@^0.3.6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/ngm-cli/-/ngm-cli-0.3.6.tgz#790a1f1b9153295973d729f542baa61cf7552ce4"
dependencies:
"@angular/compiler-cli" "^2.2.0"
"@angular/tsc-wrapped" "0.4.0"
awesome-typescript-loader "3.0.0-beta.9"
npm-submodules "0.3.4"
npm-submodules "0.3.6"
reflect-metadata "0.1.8"
rxjs "5.0.0-beta.12"
zone.js "0.7.2"
Expand Down Expand Up @@ -5168,9 +5168,9 @@ npm-run-path@^2.0.0:
dependencies:
path-key "^2.0.0"

[email protected].4:
version "0.3.4"
resolved "https://registry.yarnpkg.com/npm-submodules/-/npm-submodules-0.3.4.tgz#76a725821a743083a8a1749ae37c3b0618ffbd47"
[email protected].6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/npm-submodules/-/npm-submodules-0.3.6.tgz#b03254569f3f3acf6c7cc9d52ce31cbb65fe3f00"
dependencies:
"@angular/compiler" "^2.2.0"
"@angular/core" "^2.2.0"
Expand All @@ -5190,7 +5190,7 @@ [email protected]:
split "1.0.0"
stream-to-observable "0.2.0"
tsconfig "5.0.3"
typescript "2.0.10"
typescript "2.1.1"
update-notifier "1.0.2"
webpack "2.1.0-beta.27"
write-pkg "2.0.0"
Expand Down Expand Up @@ -7471,6 +7471,10 @@ [email protected]:
version "2.0.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.0.6.tgz#5385499ac9811508c2c43e0ea07a1ddca435e111"

[email protected]:
version "2.1.1"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.1.tgz#41c2b64472f529331b2055c0424862b44ce58d42"

[email protected]:
version "0.7.10"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.10.tgz#917559ddcce07cbc09ece7d80495e4c268f4ef9f"
Expand Down

0 comments on commit ea1de3c

Please sign in to comment.