Skip to content

Commit 9deb152

Browse files
committed
fix tests, cleanup code
1 parent ee8b79f commit 9deb152

File tree

6 files changed

+24
-32
lines changed

6 files changed

+24
-32
lines changed

packages/angular-table/src/flex-render.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
7373
) {}
7474

7575
ngOnChanges(changes: SimpleChanges) {
76-
console.log('changes', changes)
7776
if (changes['content']) {
7877
this.renderFlags |= FlexRenderFlags.ContentChanged
7978
}
@@ -101,7 +100,7 @@ export class FlexRenderDirective<TProps extends NonNullable<unknown>>
101100
const contentToRender = this.#getContentValue(this.props)
102101

103102
if (contentToRender.kind === 'null' || !this.renderView) {
104-
this.renderFlags = FlexRenderFlags.Creation
103+
this.renderFlags |= FlexRenderFlags.Creation
105104
} else {
106105
this.renderView.setContent(contentToRender.content)
107106
const previousContentInfo = this.renderView.previousContent

packages/angular-table/src/flex-render/flags.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ export enum FlexRenderFlags {
44
*/
55
Creation = 1 << 0,
66
/**
7-
* Whether the `content` property has changed or the view need a complete re-rendering.
7+
* Indicates that the `content` property has changed or the view need a complete re-rendering.
88
* When this flag is enabled, the view is recreated from scratch after clearing the previous one.
99
*/
1010
ContentChanged = 1 << 1,
1111
/**
12-
* Whether the `props` property reference has changed.
12+
* Indicates that the `props` property reference has changed.
1313
* When this flag is enabled, the view context is updated based on the type of the content.
1414
*
1515
* For Component view, inputs will be updated and view will be marked as dirty.
1616
* For TemplateRef and primitive values, view will be marked as dirty
1717
*/
1818
PropsReferenceChanged = 1 << 2,
1919
/**
20-
* Whether the current rendered view has to be dirty checked.
20+
* Indicates the current rendered view has to be dirty checked.
2121
*/
2222
DirtyCheck = 1 << 3,
2323
}

packages/angular-table/src/flex-render/flex-render-component-ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ export class FlexRenderComponentRef<T> {
6868
*
6969
* @param compare Whether the current ref component instance is the same as the given one
7070
*/
71-
eq(compare: FlexRenderComponent<T>): boolean {
71+
eqType(compare: FlexRenderComponent<T>): boolean {
7272
return compare.component === this.component
7373
}
7474

7575
/**
7676
* Tries to update current component refs input by the new given content component.
7777
*/
7878
update(content: FlexRenderComponent<T>) {
79-
const eq = this.eq(content)
79+
const eq = this.eqType(content)
8080
if (!eq) return
8181
const changes = this.diff(content)
8282
if (!changes) return

packages/angular-table/src/flex-render/view.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ export class FlexRenderTemplateView extends FlexRenderView<
8787
}
8888

8989
override dirtyCheck() {
90-
// Basically a no-op. Currently in all of those cases, we don't need to do any manual update
91-
// since this type of content is rendered with an EmbeddedViewRef with a proxy as a context,
92-
// then every time the root component is checked for changes, the getter will be re-evaluated.
90+
// Basically a no-op. When the view is created via EmbeddedViewRef, we don't need to do any manual update
91+
// since this type of content has a proxy as a context, then every time the root component is checked for changes,
92+
// the property getter will be re-evaluated.
93+
//
94+
// If in a future we need to manually mark the view as dirty, just uncomment next line
95+
// this.view.markForCheck()
9396
}
9497
}
9598

@@ -110,13 +113,16 @@ export class FlexRenderComponentView extends FlexRenderView<
110113
override dirtyCheck() {
111114
switch (this.content.kind) {
112115
case 'component': {
116+
// Component context is currently valuated with the cell context. Since it's reference
117+
// shouldn't change, we force mark the component as dirty in order to re-evaluate function invocation in view.
118+
// NOTE: this should behave like having a component with ChangeDetectionStrategy.Default
113119
this.view.markAsDirty()
114120
break
115121
}
116122
case 'flexRenderComponent': {
117-
// the given content instance will always have a different reference that previous one,
118-
// then in that case instead of recreating the entire view, we will only update what changes
119-
if (this.view.eq(this.content.content)) {
123+
// Given context instance will always have a different reference than the previous one,
124+
// so instead of recreating the entire view, we will only update the current view
125+
if (this.view.eqType(this.content.content)) {
120126
this.view.update(this.content.content)
121127
}
122128
break

packages/angular-table/tests/createAngularTable.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from '../src/index'
88
import { Component, input, isSignal, signal, untracked } from '@angular/core'
99
import { TestBed } from '@angular/core/testing'
10-
import { setSignalInputs } from './test-utils'
10+
import { setFixtureSignalInputs } from './test-utils'
1111

1212
describe('createAngularTable', () => {
1313
test('should render with required signal inputs', () => {
@@ -27,7 +27,7 @@ describe('createAngularTable', () => {
2727
}
2828

2929
const fixture = TestBed.createComponent(FakeComponent)
30-
setSignalInputs(fixture.componentInstance, {
30+
setFixtureSignalInputs(fixture, {
3131
data: [],
3232
})
3333

packages/angular-table/tests/test-utils.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,14 @@ type ToSignalInputUpdatableMap<T> = {
88
: never]: T[K] extends InputSignal<infer Value> ? Value : never
99
}
1010

11-
/**
12-
* Set required signal input value to component fixture
13-
* @see https://github.com/angular/angular/issues/54013
14-
*/
15-
export function setSignalInputs<T extends NonNullable<unknown>>(
16-
component: T,
17-
inputs: ToSignalInputUpdatableMap<T>
18-
) {
19-
for (const inputKey in inputs) {
20-
if (componentHasSignalInputProperty(component, inputKey)) {
21-
signalSetFn(component[inputKey][SIGNAL], inputs[inputKey])
22-
}
23-
}
24-
}
25-
2611
export function setFixtureSignalInputs<T extends NonNullable<unknown>>(
2712
componentFixture: ComponentFixture<T>,
2813
inputs: ToSignalInputUpdatableMap<T>,
2914
options: { detectChanges: boolean } = { detectChanges: true }
3015
) {
31-
setSignalInputs(componentFixture.componentInstance, inputs)
16+
for (const inputKey in inputs) {
17+
componentFixture.componentRef.setInput(inputKey, inputs[inputKey])
18+
}
3219
if (options.detectChanges) {
3320
componentFixture.detectChanges()
3421
}
@@ -43,7 +30,7 @@ export function setFixtureSignalInput<
4330
inputName: InputName,
4431
value: InputMaps[InputName]
4532
) {
46-
setSignalInputs(componentFixture.componentInstance, {
33+
setFixtureSignalInputs(componentFixture, {
4734
[inputName]: value,
4835
} as ToSignalInputUpdatableMap<T>)
4936
}

0 commit comments

Comments
 (0)