Skip to content

Commit 932334b

Browse files
author
Robert Clarke
committed
Merge remote-tracking branch 'origin/latest' into latest
2 parents 1b77d84 + 32e5651 commit 932334b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+92
-132
lines changed

packages/ag-grid-community/src/ts/context/beanStub.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IEventEmitter } from "../interfaces/iEventEmitter";
22
import { EventService } from "../eventService";
33
import { GridOptionsWrapper } from "../gridOptionsWrapper";
44
import { AgEvent } from "../events";
5-
import { PreDestroy } from "./context";
5+
import {Autowired, Context, PreDestroy} from "./context";
66
import { _ } from "../utils";
77

88
export class BeanStub implements IEventEmitter {
@@ -15,6 +15,8 @@ export class BeanStub implements IEventEmitter {
1515

1616
private destroyed = false;
1717

18+
@Autowired('context') private context: Context;
19+
1820
// this was a test constructor niall built, when active, it prints after 5 seconds all beans/components that are
1921
// not destroyed. to use, create a new grid, then api.destroy() before 5 seconds. then anything that gets printed
2022
// points to a bean or component that was not properly disposed of.
@@ -30,6 +32,10 @@ export class BeanStub implements IEventEmitter {
3032
// }, 5000);
3133
// }
3234

35+
public getContext(): Context {
36+
return this.context;
37+
}
38+
3339
@PreDestroy
3440
public destroy(): void {
3541

packages/ag-grid-community/src/ts/context/context.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ILogger } from "../iLogger";
22
import { Component } from "../widgets/component";
33
import { _ } from "../utils";
4+
import {BeanStub} from "./beanStub";
45

56
// steps in booting up:
67
// 1. create all beans
@@ -95,11 +96,10 @@ export class Context {
9596
}
9697
}
9798

98-
// public createComponent(ComponentClass: new () => Component): Component {
99-
// const compInstance = new ComponentClass();
100-
// this.wireBean(compInstance);
101-
// compInstance.instantiate(this);
102-
// return compInstance;
99+
// public createBean(BeanClass: new () => any): Component {
100+
// const beanInstance = new BeanClass();
101+
// this.wireBean(beanInstance);
102+
// return beanInstance;
103103
// }
104104

105105
public wireBean(bean: any, afterPreCreateCallback?: (comp: Component) => void): void {

packages/ag-grid-community/src/ts/filter/baseFilter.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ export abstract class BaseFilter<T, P extends IFilterParams, M> extends Compone
8888
@QuerySelector('#clearButton')
8989
private eClearButton: HTMLElement;
9090

91-
@Autowired('context')
92-
public context: Context;
93-
9491
private eConditionWrapper: HTMLElement;
9592
conditionValue: string;
9693

packages/ag-grid-community/src/ts/filter/floatingFilterWrapper.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ export class FloatingFilterWrapper extends Component {
4040
`<div class="ag-header-cell" aria-hidden="true">
4141
<div ref="eFloatingFilterBody" aria-hidden="true"></div>
4242
<div class="ag-floating-filter-button" ref="eButtonWrapper" aria-hidden="true">
43-
<button type="button" (click)="showParentFilter" ref="eButtonShowMainFilter"></button>
43+
<button type="button" ref="eButtonShowMainFilter"></button>
4444
</div>
4545
</div>`;
4646

47-
@Autowired('context') private context: Context;
4847
@Autowired('columnHoverService') private columnHoverService: ColumnHoverService;
4948
@Autowired('eventService') private eventService: EventService;
5049
@Autowired('beans') private beans: Beans;
@@ -72,26 +71,31 @@ export class FloatingFilterWrapper extends Component {
7271

7372
@PostConstruct
7473
private postConstruct(): void {
75-
this.instantiate(this.context);
7674

7775
this.setupFloatingFilter();
7876
this.setupWidth();
7977
this.setupLeftPositioning();
8078
this.setupColumnHover();
81-
this.addFeature(this.context, new HoverFeature([this.column], this.getGui()));
79+
this.addFeature(this.getContext(), new HoverFeature([this.column], this.getGui()));
80+
81+
this.addDestroyableEventListener(this.eButtonShowMainFilter, 'click', this.showParentFilter.bind(this));
8282
}
8383

8484
private setupFloatingFilter(): void {
8585
const colDef = this.column.getColDef();
8686
if (colDef.filter) {
8787
this.floatingFilterCompPromise = this.getFloatingFilterInstance();
88-
this.floatingFilterCompPromise.then(compInstance => {
89-
if (compInstance) {
90-
this.setupWithFloatingFilter(compInstance);
91-
} else {
92-
this.setupEmpty();
93-
}
94-
});
88+
if (this.floatingFilterCompPromise) {
89+
this.floatingFilterCompPromise.then(compInstance => {
90+
if (compInstance) {
91+
this.setupWithFloatingFilter(compInstance);
92+
} else {
93+
this.setupEmpty();
94+
}
95+
});
96+
} else {
97+
this.setupEmpty();
98+
}
9599
this.setupSyncWithFilter();
96100
} else {
97101
this.setupEmpty();

packages/ag-grid-community/src/ts/gridCore.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export class GridCore extends Component {
6161
@Autowired('quickFilterOnScope') private quickFilterOnScope: string;
6262
@Autowired('popupService') private popupService: PopupService;
6363
@Autowired('focusedCellController') private focusedCellController: FocusedCellController;
64-
@Autowired('context') private context: Context;
6564
@Autowired('loggerFactory') loggerFactory: LoggerFactory;
6665

6766
@Autowired('columnApi') private columnApi: ColumnApi;
@@ -84,7 +83,6 @@ export class GridCore extends Component {
8483

8584
const template = this.enterprise ? GridCore.TEMPLATE_ENTERPRISE : GridCore.TEMPLATE_NORMAL;
8685
this.setTemplate(template);
87-
this.instantiate(this.context);
8886

8987
// register with services that need grid core
9088
[

packages/ag-grid-community/src/ts/gridPanel/gridPanel.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export class GridPanel extends Component {
108108
@Autowired('rowRenderer') private rowRenderer: RowRenderer;
109109
@Autowired('pinnedRowModel') private pinnedRowModel: PinnedRowModel;
110110
@Autowired('eventService') private eventService: EventService;
111-
@Autowired('context') private context: Context;
112111
@Autowired('animationFrameService') private animationFrameService: AnimationFrameService;
113112
@Autowired('navigationService') private navigationService: NavigationService;
114113
@Autowired('autoHeightCalculator') private autoHeightCalculator: AutoHeightCalculator;
@@ -235,7 +234,6 @@ export class GridPanel extends Component {
235234

236235
@PostConstruct
237236
private init() {
238-
this.instantiate(this.context);
239237

240238
this.scrollWidth = this.gridOptionsWrapper.getScrollbarWidth();
241239
this.enableRtl = this.gridOptionsWrapper.isEnableRtl();
@@ -326,7 +324,7 @@ export class GridPanel extends Component {
326324
private addRowDragListener(): void {
327325
const rowDragFeature = new RowDragFeature(this.eBodyViewport, this);
328326

329-
this.context.wireBean(rowDragFeature);
327+
this.getContext().wireBean(rowDragFeature);
330328
this.dragAndDropService.addDropTarget(rowDragFeature);
331329
}
332330

@@ -1091,7 +1089,7 @@ export class GridPanel extends Component {
10911089

10921090
_.iterateObject(this.rowContainerComponents, (key: string, container: RowContainerComponent) => {
10931091
if (container) {
1094-
this.context.wireBean(container);
1092+
this.getContext().wireBean(container);
10951093
}
10961094
});
10971095
}

packages/ag-grid-community/src/ts/headerRendering/header/headerWrapperComp.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class HeaderWrapperComp extends Component {
4141
@Autowired('dragAndDropService') private dragAndDropService: DragAndDropService;
4242
@Autowired('columnController') private columnController: ColumnController;
4343
@Autowired('horizontalResizeService') private horizontalResizeService: HorizontalResizeService;
44-
@Autowired('context') private context: Context;
4544
@Autowired('menuFactory') private menuFactory: IMenuFactory;
4645
@Autowired('gridApi') private gridApi: GridApi;
4746
@Autowired('columnApi') private columnApi: ColumnApi;
@@ -78,7 +77,6 @@ export class HeaderWrapperComp extends Component {
7877

7978
@PostConstruct
8079
public init(): void {
81-
this.instantiate(this.context);
8280

8381
const colDef = this.getComponentHolder();
8482
const displayName = this.columnController.getDisplayNameForColumn(this.column, 'header', true);
@@ -95,12 +93,12 @@ export class HeaderWrapperComp extends Component {
9593
this.setupSortableClass(enableSorting);
9694
this.addColumnHoverListener();
9795

98-
this.addFeature(this.context, new HoverFeature([this.column], this.getGui()));
96+
this.addFeature(this.getContext(), new HoverFeature([this.column], this.getGui()));
9997

10098
this.addDestroyableEventListener(this.column, Column.EVENT_FILTER_ACTIVE_CHANGED, this.onFilterChanged.bind(this));
10199
this.onFilterChanged();
102100

103-
this.addFeature(this.context, new SelectAllFeature(this.cbSelectAll, this.column));
101+
this.addFeature(this.getContext(), new SelectAllFeature(this.cbSelectAll, this.column));
104102

105103
const setLeftFeature = new SetLeftFeature(this.column, this.getGui(), this.beans);
106104
setLeftFeature.init();

packages/ag-grid-community/src/ts/headerRendering/headerGroup/headerGroupWrapperComp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class HeaderGroupWrapperComp extends Component {
3434
@Autowired('columnController') private columnController: ColumnController;
3535
@Autowired('horizontalResizeService') private horizontalResizeService: HorizontalResizeService;
3636
@Autowired('dragAndDropService') private dragAndDropService: DragAndDropService;
37-
@Autowired('context') private context: Context;
3837
@Autowired('componentRecipes') private componentRecipes: ComponentRecipes;
3938
@Autowired('gridApi') private gridApi: GridApi;
4039
@Autowired('columnApi') private columnApi: ColumnApi;
@@ -80,7 +79,7 @@ export class HeaderGroupWrapperComp extends Component {
8079
this.setupMovingCss();
8180
this.setupTooltip();
8281

83-
this.addFeature(this.context, new HoverFeature(this.columnGroup.getOriginalColumnGroup().getLeafColumns(), this.getGui()));
82+
this.addFeature(this.getContext(), new HoverFeature(this.columnGroup.getOriginalColumnGroup().getLeafColumns(), this.getGui()));
8483

8584
const setLeftFeature = new SetLeftFeature(this.columnGroup, this.getGui(), this.beans);
8685
setLeftFeature.init();

packages/ag-grid-community/src/ts/headerRendering/headerRootComp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export class HeaderRootComp extends Component {
3131

3232
@Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
3333
@Autowired('columnController') private columnController: ColumnController;
34-
@Autowired('context') private context: Context;
3534
@Autowired('eventService') private eventService: EventService;
3635
@Autowired('gridApi') private gridApi: GridApi;
3736
@Autowired('autoWidthCalculator') private autoWidthCalculator: AutoWidthCalculator;
@@ -69,7 +68,7 @@ export class HeaderRootComp extends Component {
6968

7069
this.childContainers = [centerContainer, pinnedLeftContainer, pinnedRightContainer];
7170

72-
this.childContainers.forEach(container => this.context.wireBean(container));
71+
this.childContainers.forEach(container => this.getContext().wireBean(container));
7372

7473
// shotgun way to get labels to change, eg from sum(amount) to avg(amount)
7574
this.addDestroyableEventListener(this.eventService, Events.EVENT_COLUMN_VALUE_CHANGED, this.refreshHeader.bind(this));

packages/ag-grid-community/src/ts/headerRendering/headerRowComp.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class HeaderRowComp extends Component {
2727
@Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
2828
@Autowired('gridApi') private gridApi: GridApi;
2929
@Autowired('columnController') private columnController: ColumnController;
30-
@Autowired('context') private context: Context;
3130
@Autowired('eventService') private eventService: EventService;
3231
@Autowired('filterManager') private filterManager: FilterManager;
3332
@Autowired('componentRecipes') private componentRecipes: ComponentRecipes;
@@ -261,7 +260,7 @@ export class HeaderRowComp extends Component {
261260
break;
262261
}
263262

264-
this.context.wireBean(result);
263+
this.getContext().wireBean(result);
265264

266265
return result;
267266
}

packages/ag-grid-community/src/ts/rendering/cellRenderers/groupCellRenderer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export class GroupCellRenderer extends Component implements ICellRenderer {
4444
@Autowired('eventService') private eventService: EventService;
4545
@Autowired('cellRendererService') private cellRendererService: CellRendererService;
4646
@Autowired('valueFormatterService') private valueFormatterService: ValueFormatterService;
47-
@Autowired('context') private context: Context;
4847
@Autowired('columnController') private columnController: ColumnController;
4948
@Autowired('mouseEventService') private mouseEventService: MouseEventService;
5049

@@ -296,7 +295,7 @@ export class GroupCellRenderer extends Component implements ICellRenderer {
296295
&& !rowNode.detail;
297296
if (checkboxNeeded) {
298297
const cbSelectionComponent = new CheckboxSelectionComponent();
299-
this.context.wireBean(cbSelectionComponent);
298+
this.getContext().wireBean(cbSelectionComponent);
300299
cbSelectionComponent.init({rowNode: rowNode, column: this.params.column});
301300
this.eCheckbox.appendChild(cbSelectionComponent.getGui());
302301
this.addDestroyFunc(() => cbSelectionComponent.destroy());

packages/ag-grid-community/src/ts/rendering/rowRenderer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export class RowRenderer extends BeanStub {
4444
@Autowired("valueService") private valueService: ValueService;
4545
@Autowired("eventService") private eventService: EventService;
4646
@Autowired("pinnedRowModel") private pinnedRowModel: PinnedRowModel;
47-
@Autowired("context") private context: Context;
4847
@Autowired("loggerFactory") private loggerFactory: LoggerFactory;
4948
@Autowired("focusedCellController") private focusedCellController: FocusedCellController;
5049
@Autowired("cellNavigationService") private cellNavigationService: CellNavigationService;

packages/ag-grid-community/src/ts/rowModels/infinite/infiniteBlock.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { _ } from "../../utils";
1111
export class InfiniteBlock extends RowNodeBlock implements IEventEmitter {
1212

1313
@Autowired('gridOptionsWrapper') private gridOptionsWrapper: GridOptionsWrapper;
14-
@Autowired('context') private context: Context;
1514
@Autowired('rowRenderer') private rowRenderer: RowRenderer;
1615

1716
private cacheParams: InfiniteCacheParams;
@@ -51,7 +50,7 @@ export class InfiniteBlock extends RowNodeBlock implements IEventEmitter {
5150
@PostConstruct
5251
protected init(): void {
5352
super.init({
54-
context: this.context,
53+
context: this.getContext(),
5554
rowRenderer: this.rowRenderer
5655
});
5756
}

packages/ag-grid-community/src/ts/rowModels/infinite/infiniteCache.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export interface InfiniteCacheParams extends RowNodeCacheParams {
1616
export class InfiniteCache extends RowNodeCache<InfiniteBlock, InfiniteCacheParams> {
1717

1818
@Autowired('eventService') private eventService: EventService;
19-
@Autowired('context') private context: Context;
2019
@Autowired('columnApi') private columnApi: ColumnApi;
2120
@Autowired('gridApi') private gridApi: GridApi;
2221

@@ -133,10 +132,8 @@ export class InfiniteCache extends RowNodeCache<InfiniteBlock, InfiniteCachePara
133132

134133
private createBlock(blockNumber: number): InfiniteBlock {
135134
const newBlock = new InfiniteBlock(blockNumber, this.cacheParams);
136-
this.context.wireBean(newBlock);
137-
135+
this.getContext().wireBean(newBlock);
138136
this.postCreateBlock(newBlock);
139-
140137
return newBlock;
141138
}
142139

packages/ag-grid-community/src/ts/rowModels/infinite/infiniteRowModel.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export class InfiniteRowModel extends BeanStub implements IRowModel {
2727
@Autowired('sortController') private sortController: SortController;
2828
@Autowired('selectionController') private selectionController: SelectionController;
2929
@Autowired('eventService') private eventService: EventService;
30-
@Autowired('context') private context: Context;
3130
@Autowired('gridApi') private gridApi: GridApi;
3231
@Autowired('columnApi') private columnApi: ColumnApi;
3332
@Autowired('rowRenderer') private rowRenderer: RowRenderer;
@@ -206,7 +205,7 @@ export class InfiniteRowModel extends BeanStub implements IRowModel {
206205
// there is a bi-directional dependency between the loader and the cache,
207206
// so we create loader here, and then pass dependencies in setDependencies() method later
208207
this.rowNodeBlockLoader = new RowNodeBlockLoader(maxConcurrentRequests, blockLoadDebounceMillis);
209-
this.context.wireBean(this.rowNodeBlockLoader);
208+
this.getContext().wireBean(this.rowNodeBlockLoader);
210209

211210
this.cacheParams = {
212211
// the user provided datasource
@@ -253,7 +252,7 @@ export class InfiniteRowModel extends BeanStub implements IRowModel {
253252
}
254253

255254
this.infiniteCache = new InfiniteCache(this.cacheParams);
256-
this.context.wireBean(this.infiniteCache);
255+
this.getContext().wireBean(this.infiniteCache);
257256

258257
this.infiniteCache.addEventListener(RowNodeCache.EVENT_CACHE_UPDATED, this.onCacheUpdated.bind(this));
259258
}

packages/ag-grid-community/src/ts/widgets/component.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Context } from "../context/context";
1+
import {Autowired, Context, PreConstruct} from "../context/context";
22
import { BeanStub } from "../context/beanStub";
33
import { IComponent } from "../interfaces/iComponent";
44
import { AgEvent } from "../events";
@@ -38,18 +38,15 @@ export class Component extends BeanStub implements IComponent<any> {
3838
return this.compId;
3939
}
4040

41-
public instantiate(context: Context): void {
42-
this.instantiateRecurse(this.getGui(), context);
43-
}
44-
45-
private instantiateRecurse(parentNode: Element, context: Context): void {
41+
// for registered components only, eg creates AgCheckbox instance from ag-checkbox HTML tag
42+
private createChildComponentsFromTags(parentNode: Element): void {
4643

4744
// we MUST take a copy of the list first, as the 'swapComponentForNode' adds comments into the DOM
4845
// which messes up the traversal order of the children.
4946
const childNodeList: Node[] = _.copyNodeList(parentNode.childNodes);
5047

5148
childNodeList.forEach(childNode => {
52-
const childComp = context.createComponentFromElement(childNode as Element, (childComp) => {
49+
const childComp = this.getContext().createComponentFromElement(childNode as Element, (childComp) => {
5350
// copy over all attributes, including css classes, so any attributes user put on the tag
5451
// wll be carried across
5552
this.copyAttributesFromNode(childNode as Element, childComp.getGui());
@@ -58,7 +55,7 @@ export class Component extends BeanStub implements IComponent<any> {
5855
// replace the tag (eg ag-checkbox) with the proper HTMLElement (eg 'div') in the dom
5956
this.swapComponentForNode(childComp, parentNode, childNode);
6057
} else if (childNode.childNodes) {
61-
this.instantiateRecurse(childNode as Element, context);
58+
this.createChildComponentsFromTags(childNode as Element);
6259
}
6360
});
6461
}
@@ -110,6 +107,22 @@ export class Component extends BeanStub implements IComponent<any> {
110107
(this.eGui as any).__agComponent = this;
111108
this.addAnnotatedEventListeners();
112109
this.wireQuerySelectors();
110+
111+
// context will not be available when user sets template in constructor
112+
const contextIsAvailable = !!this.getContext();
113+
if (contextIsAvailable) {
114+
this.createChildComponentsFromTags(this.getGui());
115+
}
116+
}
117+
118+
@PreConstruct
119+
private createChildComponentsPreConstruct(): void {
120+
// ui exists if user sets template in constructor. when this happens, we have to wait for the context
121+
// to be autoWired first before we can create child components.
122+
const uiExists = !!this.getGui();
123+
if (uiExists) {
124+
this.createChildComponentsFromTags(this.getGui());
125+
}
113126
}
114127

115128
protected wireQuerySelectors(): void {

0 commit comments

Comments
 (0)