56
expect(fooCalled).toBe(false);
57
expect(barCalled).toBe(false);
58
// Do one step of work.
59
- ReactNoop.flushLowPri(7);
59
+ ReactNoop.flushDeferredPri(7);
60
expect(fooCalled).toBe(true);
61
expect(barCalled).toBe(false);
62
// Do the rest of the work.
63
- ReactNoop.flushLowPri(50);
63
+ ReactNoop.flushDeferredPri(50);
64
expect(fooCalled).toBe(true);
65
expect(barCalled).toBe(true);
66
});
143
144
ReactNoop.render(<Foo text="bar" />);
145
// Flush part of the work
146
- ReactNoop.flushLowPri(20);
146
+ ReactNoop.flushDeferredPri(20);
147
148
expect(ops).toEqual(['Foo', 'Bar']);
149
153
ReactNoop.render(<Foo text="baz" />);
154
155
// Flush part of the new work
156
- ReactNoop.flushLowPri(20);
156
+ ReactNoop.flushDeferredPri(20);
157
158
expect(ops).toEqual(['Foo', 'Bar']);
159
205
// Render part of the work. This should be enough to flush everything except
206
// the middle which has lower priority.
207
ReactNoop.render(<Foo text="bar" />);
208
- ReactNoop.flushLowPri(40);
208
+ ReactNoop.flushDeferredPri(40);
209
210
expect(ops).toEqual(['Foo', 'Bar', 'Bar']);
211
218
219
});
220
221
+ it('can deprioritize a tree from without dropping work', () => {
222
+ var ops = [];
223
+
224
+ function Bar(props) {
225
+ ops.push('Bar');
226
+ return <div>{props.children}</div>;
227
+ }
228
+
229
+ function Middle(props) {
230
+ ops.push('Middle');
231
+ return <span>{props.children}</span>;
232
+ }
233
+
234
+ function Foo(props) {
235
+ ops.push('Foo');
236
+ return (
237
+ <div>
238
+ <Bar>{props.text}</Bar>
239
+ <section hidden={true}>
240
+ <Middle>{props.text}</Middle>
241
+ </section>
242
+ <Bar>{props.text}</Bar>
243
+ <footer hidden={true}>
244
+ <Middle>Footer</Middle>
245
+ </footer>
246
+ </div>
247
+ );
248
+ }
249
+
250
+ // Init
251
+ ReactNoop.performAnimationWork(() => {
252
+ ReactNoop.render(<Foo text="foo" />);
253
+ });
254
+ ReactNoop.flush();
255
+
256
+ expect(ops).toEqual(['Foo', 'Bar', 'Bar', 'Middle', 'Middle']);
257
+
258
+ ops = [];
259
+
260
+ // Render the high priority work (everying except the hidden trees).
261
+ ReactNoop.performAnimationWork(() => {
262
+ ReactNoop.render(<Foo text="foo" />);
263
+ });
264
+ ReactNoop.render(<Foo text="bar" />);
265
+ ReactNoop.flushAnimationPri();
266
+
267
+ expect(ops).toEqual(['Foo', 'Bar', 'Bar']);
268
+
269
+ ops = [];
270
+
271
+ // The hidden content was deprioritized from high to low priority. A low
272
+ // priority callback should have been scheduled. Flush it now.
273
+ ReactNoop.flushDeferredPri();
274
+
275
+ expect(ops).toEqual(['Middle', 'Middle']);
276
+ });
277
+
278
it('can resume work in a subtree even when a parent bails out', () => {
279
280
var ops = [];
320
321
// Init
322
ReactNoop.render(<Foo text="foo" />);
266
- ReactNoop.flushLowPri(52);
323
+ ReactNoop.flushDeferredPri(52);
324
325
expect(ops).toEqual(['Foo', 'Bar', 'Tester', 'Bar']);
326
328
329
// We're now rendering an update that will bail out on updating middle.
330
ReactNoop.render(<Foo text="bar" />);
274
- ReactNoop.flushLowPri(45);
331
+ ReactNoop.flushDeferredPri(45);
332
333
expect(ops).toEqual(['Foo', 'Bar', 'Bar']);
334
395
396
// Init
397
ReactNoop.render(<Foo text="foo" />);
341
- ReactNoop.flushLowPri(52);
398
+ ReactNoop.flushDeferredPri(52);
399
400
expect(ops).toEqual(['Foo', 'Bar', 'Tester', 'Bar']);
401
404
// Make a quick update which will create a low pri tree on top of the
405
// already low pri tree.
406
ReactNoop.render(<Foo text="bar" />);
350
- ReactNoop.flushLowPri(15);
407
+ ReactNoop.flushDeferredPri(15);
408
409
expect(ops).toEqual(['Foo']);
410
467
468
// Init
469
ReactNoop.render(<Foo text="foo" text2="foo" step={0} />);
413
- ReactNoop.flushLowPri(55 + 25);
470
+ ReactNoop.flushDeferredPri(55 + 25);
471
472
// We only finish the higher priority work. So the low pri content
473
// has not yet finished mounting.
489
// Make a quick update which will schedule low priority work to
490
// update the middle content.
491
ReactNoop.render(<Foo text="bar" text2="bar" step={1} />);
435
- ReactNoop.flushLowPri(30 + 25);
492
+ ReactNoop.flushDeferredPri(30 + 25);
493
494
expect(ops).toEqual(['Foo', 'Bar']);
495
496
ops = [];
497
498
// The middle content is now pending rendering...
442
- ReactNoop.flushLowPri(30);
499
+ ReactNoop.flushDeferredPri(30);
500
expect(ops).toEqual(['Middle', 'Bar']);
501
502
ops = [];
504
// but we'll interupt it to render some higher priority work.
505
// The middle content will bailout so it remains untouched.
506
ReactNoop.render(<Foo text="foo" text2="bar" step={1} />);
450
- ReactNoop.flushLowPri(30);
507
+ ReactNoop.flushDeferredPri(30);
508
509
expect(ops).toEqual(['Foo', 'Bar']);
510
576
// Make a quick update which will schedule low priority work to
577
// update the middle content.
578
ReactNoop.render(<Foo text="bar" step={1} />);
522
- ReactNoop.flushLowPri(30);
579
+ ReactNoop.flushDeferredPri(30);
580
581
expect(ops).toEqual(['Foo', 'Bar']);
582
583
ops = [];
584
585
// The middle content is now pending rendering...
529
- ReactNoop.flushLowPri(30 + 25);
586
+ ReactNoop.flushDeferredPri(30 + 25);
587
expect(ops).toEqual(['Content', 'Middle', 'Bar']); // One more Middle left.
588
589
ops = [];
591
// but we'll interupt it to render some higher priority work.
592
// The middle content will bailout so it remains untouched.
593
ReactNoop.render(<Foo text="foo" step={1} />);
537
- ReactNoop.flushLowPri(30);
594
+ ReactNoop.flushDeferredPri(30);
595
596
expect(ops).toEqual(['Foo', 'Bar']);
597