Skip to content

Commit

Permalink
refactor(angular-virtual): add eslint & fix all eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettld committed Aug 26, 2024
1 parent 236b312 commit 7b5081f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
5 changes: 5 additions & 0 deletions packages/angular-virtual/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @ts-check

import rootConfig from '../../eslint.config.js'

export default [...rootConfig]
1 change: 1 addition & 0 deletions packages/angular-virtual/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"scripts": {
"clean": "rimraf ./build",
"test:types": "tsc --noEmit",
"test:eslint": "eslint ./src",
"build": "ng-packagr -p ng-package.json -c tsconfig.build.json"
},
"dependencies": {
Expand Down
36 changes: 18 additions & 18 deletions packages/angular-virtual/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import {
AfterRenderPhase,
DestroyRef,
type ElementRef,
type Signal,
afterNextRender,
computed,
effect,
inject,
signal,
untracked,
} from '@angular/core'
import {
type PartialKeys,
Virtualizer,
type VirtualizerOptions,
elementScroll,
observeElementOffset,
observeElementRect,
observeWindowOffset,
observeWindowRect,
PartialKeys,
Virtualizer,
VirtualizerOptions,
windowScroll,
} from '@tanstack/virtual-core'
import { proxyVirtualizer } from './proxy'
import type { AngularVirtualizer } from './types'

export * from '@tanstack/virtual-core'
export * from './types'

import {
signal,
inject,
DestroyRef,
computed,
Signal,
effect,
ElementRef,
afterNextRender,
untracked,
AfterRenderPhase,
} from '@angular/core'
import { AngularVirtualizer } from './types'
import { proxyVirtualizer } from './proxy'

function createVirtualizerBase<
TScrollElement extends Element | Window,
TItemElement extends Element,
Expand Down
15 changes: 10 additions & 5 deletions packages/angular-virtual/src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Signal, WritableSignal, computed, untracked } from '@angular/core'
import { Virtualizer } from '@tanstack/virtual-core'
import { AngularVirtualizer } from './types'
import {
type Signal,
type WritableSignal,
computed,
untracked,
} from '@angular/core'
import { type Virtualizer } from '@tanstack/virtual-core'
import { type AngularVirtualizer } from './types'

export function proxyVirtualizer<
V extends Virtualizer<any, any>,
Expand Down Expand Up @@ -94,7 +99,7 @@ function toComputed<V extends Virtualizer<any, any>>(
) {
const computedCache: Record<string, Signal<unknown>> = {}

return (...args: any[]) => {
return (...args: Array<any>) => {
// Cache computeds by their arguments to avoid re-creating the computed on each call
const serializedArgs = serializeArgs(...args)
if (computedCache.hasOwnProperty(serializedArgs)) {
Expand All @@ -111,6 +116,6 @@ function toComputed<V extends Virtualizer<any, any>>(
}
}

function serializeArgs(...args: any[]) {
function serializeArgs(...args: Array<any>) {
return JSON.stringify(args)
}
4 changes: 2 additions & 2 deletions packages/angular-virtual/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Signal } from '@angular/core'
import { Virtualizer } from '@tanstack/virtual-core'
import type { Signal } from '@angular/core'
import type { Virtualizer } from '@tanstack/virtual-core'

export type AngularVirtualizer<
TScrollElement extends Element | Window,
Expand Down
3 changes: 1 addition & 2 deletions packages/angular-virtual/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./build/lib"
},
"angularCompilerOptions": {
"compilationMode": "partial"
},
"include": ["src"],
"include": ["src", "eslint.config.js"],
"exclude": ["**/*.spec.ts"]
}

0 comments on commit 7b5081f

Please sign in to comment.