-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react): add SSR support to React apps (#13234)
- Loading branch information
Showing
32 changed files
with
741 additions
and
144 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
53 changes: 53 additions & 0 deletions
53
packages/js/src/utils/async-iterable/combine-async-iteratables-iterators.spec.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,53 @@ | ||
import { combineAsyncIterableIterators } from './combine-async-iteratable-iterators'; | ||
|
||
function delay(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
describe('combineAsyncIterators', () => { | ||
it('should merge iterators', async () => { | ||
async function* a() { | ||
await delay(20); | ||
yield 'a'; | ||
} | ||
|
||
async function* b() { | ||
await delay(0); | ||
yield 'b'; | ||
} | ||
|
||
const c = combineAsyncIterableIterators(a(), b()); | ||
const results = []; | ||
|
||
for await (const x of c) { | ||
results.push(x); | ||
} | ||
|
||
expect(results).toEqual(['b', 'a']); | ||
}); | ||
|
||
it('should throw when one iterator throws', async () => { | ||
async function* a() { | ||
await delay(20); | ||
yield 'a'; | ||
} | ||
|
||
async function* b() { | ||
throw new Error('threw in b'); | ||
} | ||
|
||
const c = combineAsyncIterableIterators(a(), b()); | ||
|
||
async function* d() { | ||
yield* c; | ||
} | ||
|
||
try { | ||
for await (const x of d()) { | ||
} | ||
throw new Error('should not reach here'); | ||
} catch (e) { | ||
expect(e.message).toMatch(/threw in b/); | ||
} | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
...nc-iterable/create-async-iterable.spec.ts → ...nc-iterable/create-async-iterable.spec.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
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
packages/js/src/utils/async-iterable/map-async-iteratable.spec.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,20 @@ | ||
import { mapAsyncIterable } from './map-async-iteratable'; | ||
|
||
describe('mapAsyncIterator', () => { | ||
it('should map over values', async () => { | ||
async function* f() { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
const c = mapAsyncIterable(f(), (x) => x * 2); | ||
const results = []; | ||
|
||
for await (const x of c) { | ||
results.push(x); | ||
} | ||
|
||
expect(results).toEqual([2, 4, 6]); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/js/src/utils/async-iterable/map-async-iteratable.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,22 @@ | ||
export async function* mapAsyncIterable<T = any, I = any, O = any>( | ||
data: AsyncIterable<T> | AsyncIterableIterator<T>, | ||
transform: ( | ||
input: I, | ||
index?: number, | ||
data?: AsyncIterable<T> | AsyncIterableIterator<T> | ||
) => O | ||
) { | ||
async function* f() { | ||
const generator = data[Symbol.asyncIterator] || data[Symbol.iterator]; | ||
const iterator = generator.call(data); | ||
let index = 0; | ||
let item = await iterator.next(); | ||
while (!item.done) { | ||
yield await transform(await item.value, index, data); | ||
index++; | ||
item = await iterator.next(); | ||
} | ||
} | ||
|
||
return yield* f(); | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/js/src/utils/async-iterable/tap-async-iteratable.spec.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,25 @@ | ||
import { tapAsyncIterator } from './tap-async-iteratable'; | ||
|
||
describe('tapAsyncIterator', () => { | ||
it('should tap values', async () => { | ||
async function* f() { | ||
yield 1; | ||
yield 2; | ||
yield 3; | ||
} | ||
|
||
const tapped = []; | ||
const results = []; | ||
|
||
const c = tapAsyncIterator(f(), (x) => { | ||
tapped.push(`tap: ${x}`); | ||
}); | ||
|
||
for await (const x of c) { | ||
results.push(x); | ||
} | ||
|
||
expect(tapped).toEqual(['tap: 1', 'tap: 2', 'tap: 3']); | ||
expect(results).toEqual([1, 2, 3]); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/js/src/utils/async-iterable/tap-async-iteratable.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,11 @@ | ||
import { mapAsyncIterable } from './map-async-iteratable'; | ||
|
||
export async function* tapAsyncIterator<T = any, I = any, O = any>( | ||
data: AsyncIterable<T> | AsyncIterableIterator<T>, | ||
fn: (input: I) => void | ||
) { | ||
return yield* mapAsyncIterable(data, (x) => { | ||
fn(x); | ||
return x; | ||
}); | ||
} |
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.
23e4fc7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-five.vercel.app