-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(native): Reduce chance of frame drops with InteractionManager (…
- Loading branch information
Showing
17 changed files
with
117 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@data-client/react': patch | ||
--- | ||
|
||
React Native calls fetches in InteractionManager.runAfterInteractions callback | ||
|
||
This reduces the chance of frame drops. |
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,5 @@ | ||
--- | ||
'@data-client/core': patch | ||
--- | ||
|
||
Remove RIC export |
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 @@ | ||
--- | ||
'@data-client/core': patch | ||
--- | ||
|
||
Add NetworkManager.idleCallback overridable method | ||
|
||
This allows platform specific implementations by overriding the method. | ||
For instance, on web: | ||
|
||
```ts | ||
import { NetworkManager } from '@data-client/core'; | ||
|
||
export default class WebNetworkManager extends NetworkManager { | ||
static { | ||
if (typeof requestIdleCallback === 'function') { | ||
WebNetworkManager.prototype.idleCallback = requestIdleCallback; | ||
} | ||
} | ||
} | ||
``` |
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,3 +1,2 @@ | ||
export { MemoCache, INVALID } from '@data-client/normalizr'; | ||
export { default as RIC } from './state/RIC.js'; | ||
export { initialState } from './state/reducer/createReducer.js'; |
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 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
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,18 @@ | ||
import { NetworkManager } from '@data-client/core'; | ||
import { InteractionManager } from 'react-native'; | ||
|
||
export default class NativeNetworkManager extends NetworkManager { | ||
/** Calls the callback when client is not 'busy' with high priority interaction tasks | ||
* | ||
* Override for platform-specific implementations | ||
*/ | ||
protected idleCallback( | ||
callback: (...args: any[]) => void, | ||
options?: IdleRequestOptions, | ||
) { | ||
InteractionManager.runAfterInteractions(callback); | ||
if (options?.timeout) { | ||
InteractionManager.setDeadline(options.timeout); | ||
} | ||
} | ||
} |
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,9 @@ | ||
import { NetworkManager } from '@data-client/core'; | ||
|
||
export default class WebNetworkManager extends NetworkManager { | ||
static { | ||
if (typeof requestIdleCallback === 'function') { | ||
WebNetworkManager.prototype.idleCallback = requestIdleCallback; | ||
} | ||
} | ||
} |
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,12 @@ | ||
import { NetworkManager } from '..'; | ||
describe('RequestIdleCallback', () => { | ||
it('should run using InteractionManager', async () => { | ||
const fn = jest.fn(); | ||
jest.useFakeTimers(); | ||
// @ts-expect-error this is protected member | ||
new NetworkManager().idleCallback(fn, {}); | ||
jest.runAllTimers(); | ||
expect(fn).toHaveBeenCalled(); | ||
jest.useRealTimers(); | ||
}); | ||
}); |
9 changes: 5 additions & 4 deletions
9
packages/core/src/state/__tests__/RIC.web.ts → ...s/react/src/managers/__tests__/RIC.web.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
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,8 @@ | ||
export { | ||
PollingSubscription, | ||
DevToolsManager, | ||
SubscriptionManager, | ||
DefaultConnectionListener, | ||
LogoutManager, | ||
} from '@data-client/core'; | ||
export { default as NetworkManager } from './NetworkManager.js'; |
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