-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ngrid): use intersection observer
BREAKING CHANGE: `resize-observer-polyfill` is no longer a peerDependency and is not required by the library. If you want polyfill support please import the polyfill using polyfill.ts
- Loading branch information
1 parent
db28ef2
commit 161371b
Showing
48 changed files
with
556 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
apps/ngrid-docs-app/content/concepts/context/context-example/context-object.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<pbl-ngrid [dataSource]="ds" [columns]="columns"> | ||
|
||
<div *pblNgridCellDef="'dsIndex'; let ctx"> | ||
{{ctx.rowContext.dsIndex}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'index'; let ctx"> | ||
{{ctx.rowContext.index}} | ||
</div> | ||
|
||
|
||
<div *pblNgridCellDef="'firstRender'; let ctx"> | ||
{{!!ctx.rowContext.firstRender}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'outOfView'; let ctx"> | ||
{{!!ctx.rowContext.outOfView}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'count'; let ctx"> | ||
{{ctx.rowContext.count}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'even'; let ctx"> | ||
{{!!ctx.rowContext.even}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'odd'; let ctx"> | ||
{{!!ctx.rowContext.odd}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'first'; let ctx"> | ||
{{!!ctx.rowContext.first}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'last'; let ctx"> | ||
{{!!ctx.rowContext.last}} | ||
</div> | ||
|
||
<div *pblNgridCellDef="'identity'; let ctx"> | ||
{{ctx.rowContext.identity}} | ||
</div> | ||
|
||
</pbl-ngrid> |
Empty file.
35 changes: 35 additions & 0 deletions
35
apps/ngrid-docs-app/content/concepts/context/context-example/context-object.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core'; | ||
import { createDS, columnFactory } from '@pebula/ngrid'; | ||
|
||
import { Person, DynamicClientApi } from '@pebula/apps/docs-app-lib/client-api'; | ||
import { Example } from '@pebula/apps/docs-app-lib'; | ||
|
||
@Component({ | ||
selector: 'pbl-context-object-example', | ||
templateUrl: './context-object.component.html', | ||
styleUrls: ['./context-object.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
@Example('pbl-context-object-example', { title: 'Context Object' }) | ||
export class ContextObjectExample { | ||
columns = columnFactory() | ||
.table( | ||
{ prop: 'id', width: '50px' }, | ||
{ prop: 'name', width: '100px', pIndex: true }, | ||
{ prop: 'firstRender', width: '50px' }, | ||
{ prop: 'outOfView', width: '50px' }, | ||
{ prop: 'dsIndex', width: '50px' }, | ||
{ prop: 'index', width: '50px' }, | ||
{ prop: 'count', width: '50px' }, | ||
{ prop: 'odd', width: '50px' }, | ||
{ prop: 'even', width: '50px' }, | ||
{ prop: 'first', width: '50px' }, | ||
{ prop: 'last', width: '50px' }, | ||
{ prop: 'identity', width: '100px' }, | ||
) | ||
.build(); | ||
ds = createDS<Person>().onTrigger( () => this.datasource.getPeople(100, 500) ).create(); | ||
|
||
constructor(private datasource: DynamicClientApi) { } | ||
} |
107 changes: 107 additions & 0 deletions
107
apps/ngrid-docs-app/content/concepts/grid/browser-apis.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
title: Compatibility & Browser APIs | ||
path: concepts/grid/browser-apis | ||
parent: concepts/grid | ||
ordinal: 4 | ||
--- | ||
# Compatibility & Browser APIs | ||
|
||
## Compatibility | ||
|
||
**nGrid** support all browsers that angular & the angular CDK support. | ||
|
||
## Browser APIs | ||
|
||
**nGrid** makes use of the following browsers APIs: | ||
|
||
### ResizeObserver | ||
|
||
The [ResizeObserver API](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver) is used to detect resize in column width's and react to them by re-calculating the new widths. | ||
|
||
The **ResizeObserver API** is supported in all major browsers, however it is not supported by **Internet Explorer** | ||
If you require full support or want a polyfill just in case you can use one of the following polyfills: | ||
|
||
- [resize-observer-polyfill](https://github.com/que-etc/resize-observer-polyfill) - The most used polyfill (performs auto-detect) | ||
- [@juggle/resize-observer](https://github.com/juggle/resize-observer) - A newer, more modern polyfill (does NOT auto-detect) | ||
|
||
You can add them to your `polyfill.ts` file. | ||
|
||
I> There might be more differences between the 2, please read the documentation of each one for more in-depth information | ||
|
||
**resize-observer-polyfill** will automatically detect if the API is implemented and if not will add it so you can safely do: | ||
|
||
```typescript | ||
import 'resize-observer-polyfill'; | ||
``` | ||
|
||
In your `polyfill.ts`. | ||
|
||
Note the polyfill has built-in type support (d.ts) auto-loaded when you import it, so if you already have types | ||
loaded for `ResizeObserver` and want to keep them, load the polyfill directly without passing through the `package.json` | ||
|
||
```typescript | ||
import 'resize-observer-polyfill/dist/ResizeObserver'; | ||
``` | ||
|
||
**@juggle/resize-observer** does not auto-detect so doing the above will override the native implementation, if one exists. | ||
|
||
So you should do something like this: | ||
|
||
```typescript | ||
import { ResizeObserver as Polyfill } from '@juggle/resize-observer'; | ||
|
||
if ('ResizeObserver' in window === false) { | ||
window.ResizeObserver = Polyfill; | ||
} | ||
``` | ||
|
||
There are more options for this polyfill, including a demo how to load it async using dynamic imports, read more at the polyfill's site. | ||
|
||
I> **nGrid** makes minimal use of the API so changes in the final spec should have no effect. | ||
@types/resize-observer-brow | ||
|
||
### ResizeObserver Types | ||
|
||
If you enable library type checking and TypeScript is complaining about `ResizeObserver` types missing, install the following: | ||
|
||
```bash | ||
yarn add -D @types/resize-observer-browser | ||
|
||
# OR | ||
|
||
npm install -D @types/resize-observer-browser | ||
``` | ||
|
||
This should not happen as both polyfills come with types build in... | ||
|
||
> If you have specific `types` defined in your `tsconfig.json` add it there as well. | ||
### IntersectionObserver | ||
|
||
The [IntersectionObserver API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API) is used for performance. | ||
|
||
It allows **nGrid** to get notified when a row is visible and when it is not. | ||
With this API **nGrid** can skip a lot of layout reflows and recalculations because it does not need to check if a row is out of view. | ||
This is very important for performance, especially when using virtual scroll. | ||
|
||
The **IntersectionObserver API** is a more mature API compared to the `ResizeObserver API`, it is shipped with all major browsers for a long time now | ||
and comes as part of the DOM type library in TypeScript. | ||
|
||
That said, it is not supported in Internet Explorer. | ||
|
||
In this case we do not provide recommendation for a polyfill, you can use any good polyfill out there or you can **DISABLE** the use of the API | ||
so **nGrid** will not use it to detect the changes and instead perform it's own magic for that. This will slightly degrade performance, how much | ||
depends on the use case, **nGrid** instance configuration and features used together. | ||
|
||
To disable the use of **IntersectionObserver** apply the following provider in your application root module: | ||
|
||
```typescript | ||
import { DISABLE_INTERSECTION_OBSERVABLE } from '@pebula/ngrid'; | ||
|
||
@NgModule({ | ||
providers: [ | ||
{ provide: DISABLE_INTERSECTION_OBSERVABLE, useValue: true }, | ||
] | ||
}) | ||
class MyAppRootModule { } | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.