This repository was archived by the owner on May 19, 2023. It is now read-only.
File tree 5 files changed +20
-21
lines changed
5 files changed +20
-21
lines changed Original file line number Diff line number Diff line change 1
- import { CONCURRENT_MODE_THRESHOLD , DIRECTIVE_PREFIX , UnknownKV } from '../models/generics' ;
1
+ import { DIRECTIVE_PREFIX , UnknownKV } from '../models/generics' ;
2
2
import { ASTNode , ASTNodeType , Directives } from '../models/structs' ;
3
3
import { renderDirective } from './directive' ;
4
- import concurrent from './utils/concurrent ' ;
4
+ import fiber from './utils/fiber ' ;
5
5
import { rawDirectiveSplitRE } from './utils/patterns' ;
6
6
7
7
const render = (
@@ -12,7 +12,7 @@ const render = (
12
12
) : void => {
13
13
const legalDirectiveNames = Object . keys ( directives ) ;
14
14
15
- concurrent ( CONCURRENT_MODE_THRESHOLD , function * ( ) {
15
+ const renderFiber = fiber ( function * ( ) {
16
16
for ( const node of ast ) {
17
17
if ( node . type === ASTNodeType . NULL ) continue ;
18
18
yield ;
@@ -62,7 +62,9 @@ const render = (
62
62
node . el . dispatchEvent ( effectEvent ) ;
63
63
}
64
64
}
65
- } ) ( ) ;
65
+ } ) ;
66
+
67
+ window . requestIdleCallback ( renderFiber ) ;
66
68
} ;
67
69
68
70
export default render ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import fiber from '../fiber' ;
2
+
3
+ describe ( '.fiber' , ( ) => {
4
+ it ( 'should be a function' , ( ) => {
5
+ expect ( typeof fiber ) . toEqual ( 'function' ) ;
6
+ } ) ;
7
+ } ) ;
Original file line number Diff line number Diff line change 1
1
/* istanbul ignore file */
2
2
3
- // Concurrent allows us to delay render calls if the main thread is blocked
3
+ // Fiber allows us to delay render calls if the main thread is blocked
4
4
// This is kind of like time slicing in React but less advanced
5
5
6
- export const concurrent = (
7
- threshold : number ,
6
+ export const fiber = (
8
7
generatorFunction : ( ) => Generator < undefined , void , unknown >
9
8
// eslint-disable-next-line @typescript-eslint/ban-types
10
- ) : Function => {
9
+ ) : IdleRequestCallback => {
11
10
const generator = generatorFunction ( ) ;
12
- return function next ( ) {
13
- const start = performance . now ( ) ;
11
+ return function next ( deadline : IdleDeadline ) {
14
12
let task = null ;
15
13
do {
16
14
task = generator . next ( ) ;
17
- } while ( performance . now ( ) - start < threshold && ! task . done ) ;
15
+ } while ( ! task . done && deadline . timeRemaining ( ) > 0 ) ;
18
16
19
17
if ( task . done ) return ;
20
18
/* istanbul ignore next */
21
- setTimeout ( next ) ;
19
+ requestIdleCallback ( next ) ;
22
20
} ;
23
21
} ;
24
22
25
- export default concurrent ;
23
+ export default fiber ;
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ export const DIRECTIVE_PREFIX = 'l-';
2
2
export const COMPONENT_FLAG = 'component' ;
3
3
export const FOR_TEMPLATE_FLAG = '__for_template' ;
4
4
export const MODEL_REGISTERED_FLAG = '__model_registered' ;
5
- export const CONCURRENT_MODE_THRESHOLD = 25 ;
6
5
export enum DIRECTIVE_SHORTHANDS {
7
6
'@' = 'on' ,
8
7
':' = 'bind' ,
You can’t perform that action at this time.
0 commit comments