-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(store): move Angular Signal interop into State service (#3879)
Closes #3869
- Loading branch information
1 parent
0aa1582
commit 8cb5795
Showing
8 changed files
with
90 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Store, provideStore } from '@ngrx/store'; | ||
import { Component, inject, Pipe, PipeTransform } from '@angular/core'; | ||
|
||
@Pipe({ name: 'test', standalone: true }) | ||
export class TestPipe implements PipeTransform { | ||
store = inject(Store); | ||
|
||
transform(s: number) { | ||
this.store.select('count'); | ||
return s * 2; | ||
} | ||
} | ||
|
||
@Component({ | ||
selector: 'test-component', | ||
standalone: true, | ||
imports: [TestPipe], | ||
template: `{{ 3 | test }}`, | ||
}) | ||
export class TestComponent {} | ||
|
||
describe('NgRx Store Integration', () => { | ||
describe('with pipes', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TestComponent], | ||
providers: [ | ||
provideStore({ count: () => 2 }, { initialState: { count: 2 } }), | ||
], | ||
}); | ||
}); | ||
|
||
it('should not throw an error', () => { | ||
const component = TestBed.createComponent(TestComponent); | ||
|
||
component.detectChanges(); | ||
|
||
expect(component.nativeElement.textContent).toBe('6'); | ||
}); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Injectable, Signal } from '@angular/core'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class MockState<T> extends BehaviorSubject<T> { | ||
/** | ||
* @internal | ||
*/ | ||
readonly state: Signal<T>; | ||
|
||
constructor() { | ||
super(<T>{}); | ||
|
||
this.state = toSignal(this, { manualCleanup: true, requireSync: true }); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { inject, Pipe, PipeTransform } from '@angular/core'; | ||
import { Store } from '@ngrx/store'; | ||
|
||
@Pipe({ name: 'test', standalone: true }) | ||
export class TestPipe implements PipeTransform { | ||
store = inject(Store); | ||
transform(s: number) { | ||
this.store.select('count'); | ||
return s * 2; | ||
} | ||
} |