-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement batch rendering (#989)
- Loading branch information
Showing
25 changed files
with
227 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { getBatchedUpdates, scheduleMicrotask } from './utils' | ||
|
||
// TYPES | ||
|
||
type NotifyCallback = () => void | ||
|
||
// CLASS | ||
|
||
export class NotifyManager { | ||
private queue: NotifyCallback[] | ||
private transactions: number | ||
|
||
constructor() { | ||
this.queue = [] | ||
this.transactions = 0 | ||
} | ||
|
||
batch<T>(callback: () => T): T { | ||
this.transactions++ | ||
const result = callback() | ||
this.transactions-- | ||
if (!this.transactions) { | ||
this.flush() | ||
} | ||
return result | ||
} | ||
|
||
schedule(notify: NotifyCallback): void { | ||
if (this.transactions) { | ||
this.queue.push(notify) | ||
} else { | ||
scheduleMicrotask(() => { | ||
notify() | ||
}) | ||
} | ||
} | ||
|
||
flush(): void { | ||
const queue = this.queue | ||
this.queue = [] | ||
if (queue.length) { | ||
scheduleMicrotask(() => { | ||
const batchedUpdates = getBatchedUpdates() | ||
batchedUpdates(() => { | ||
queue.forEach(notify => { | ||
notify() | ||
}) | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
// SINGLETON | ||
|
||
export const notifyManager = new NotifyManager() |
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
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,2 +1,6 @@ | ||
import { setBatchedUpdates } from './core/index' | ||
import { unstable_batchedUpdates } from './react/reactBatchedUpdates' | ||
setBatchedUpdates(unstable_batchedUpdates) | ||
|
||
export * from './core/index' | ||
export * from './react/index' |
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,3 @@ | ||
// @ts-ignore | ||
import { unstable_batchedUpdates } from 'react-native' | ||
export { unstable_batchedUpdates } |
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,2 @@ | ||
import ReactDOM from 'react-dom' | ||
export const unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates |
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.
1267731
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: