-
-
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.
perf(component): reset state / trigger CD only if necessary (#3328)
- Loading branch information
1 parent
888eb56
commit f5b055b
Showing
19 changed files
with
1,058 additions
and
466 deletions.
There are no files selected for viewing
168 changes: 0 additions & 168 deletions
168
modules/component/spec/core/cd-aware/cd-aware_creator.spec.ts
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
modules/component/spec/core/cd-aware/render_creator.spec.ts
This file was deleted.
Oops, something went wrong.
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,55 @@ | ||
import { of } from 'rxjs'; | ||
import { TestScheduler } from 'rxjs/testing'; | ||
import { fromPotentialObservable } from '../../src/core/potential-observable'; | ||
|
||
describe('fromPotentialObservable', () => { | ||
function setup() { | ||
return { | ||
testScheduler: new TestScheduler((actual, expected) => | ||
expect(actual).toEqual(expected) | ||
), | ||
}; | ||
} | ||
|
||
function testNullishInput(input: null | undefined): void { | ||
it(`should create observable from ${input}`, () => { | ||
const { testScheduler } = setup(); | ||
|
||
testScheduler.run(({ expectObservable }) => { | ||
const obs$ = fromPotentialObservable(input); | ||
expectObservable(obs$).toBe('(x|)', { x: input }); | ||
}); | ||
}); | ||
} | ||
|
||
testNullishInput(null); | ||
|
||
testNullishInput(undefined); | ||
|
||
it('should create observable from array', () => { | ||
const { testScheduler } = setup(); | ||
const array = [1, 2, 3]; | ||
|
||
testScheduler.run(({ expectObservable }) => { | ||
const obs$ = fromPotentialObservable(array); | ||
expectObservable(obs$).toBe('(xyz|)', { x: 1, y: 2, z: 3 }); | ||
}); | ||
}); | ||
|
||
it('should create observable from promise', (done) => { | ||
const promise = Promise.resolve(100); | ||
const obs$ = fromPotentialObservable(promise); | ||
|
||
// promises cannot be tested with test scheduler | ||
obs$.subscribe((value) => { | ||
expect(value).toBe(100); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return passed observable', () => { | ||
const obs1$ = of('ngrx'); | ||
const obs2$ = fromPotentialObservable(obs1$); | ||
expect(obs1$).toBe(obs2$); | ||
}); | ||
}); |
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,55 @@ | ||
import { combineRenderEventHandlers } from '../../../src/core/render-event/handlers'; | ||
import { | ||
CompleteRenderEvent, | ||
ErrorRenderEvent, | ||
NextRenderEvent, | ||
RenderEvent, | ||
ResetRenderEvent, | ||
} from '../../../src/core/render-event/models'; | ||
|
||
describe('combineRenderEventHandlers', () => { | ||
function testRenderEvent<T>(event: RenderEvent<T>): void { | ||
describe(`when ${event.type} is emitted`, () => { | ||
it(`should call ${event.type} handler`, () => { | ||
const mockHandler = jest.fn(); | ||
const handleRenderEvent = combineRenderEventHandlers({ | ||
[event.type]: mockHandler, | ||
}); | ||
|
||
handleRenderEvent(event); | ||
expect(mockHandler).toHaveBeenCalledWith(event); | ||
}); | ||
|
||
it(`should not throw error if ${event.type} handler is not defined`, () => { | ||
const handleRenderEvent = combineRenderEventHandlers({}); | ||
expect(() => handleRenderEvent(event)).not.toThrowError(); | ||
}); | ||
}); | ||
} | ||
|
||
const resetEvent: ResetRenderEvent = { | ||
type: 'reset', | ||
reset: true, | ||
}; | ||
testRenderEvent(resetEvent); | ||
|
||
const nextEvent: NextRenderEvent<number> = { | ||
type: 'next', | ||
value: 1, | ||
reset: true, | ||
}; | ||
testRenderEvent(nextEvent); | ||
|
||
const errorEvent: ErrorRenderEvent = { | ||
type: 'error', | ||
error: 'ERROR!', | ||
reset: false, | ||
}; | ||
testRenderEvent(errorEvent); | ||
|
||
const completeEvent: CompleteRenderEvent = { | ||
type: 'complete', | ||
reset: false, | ||
}; | ||
testRenderEvent(completeEvent); | ||
}); |
Oops, something went wrong.