mirror of
https://github.com/facebook/react.git
synced 2026-02-24 12:43:00 +00:00
* Deterministic updates High priority updates typically require less work to render than low priority ones. It's beneficial to flush those first, in their own batch, before working on more expensive low priority ones. We do this even if a high priority is scheduled after a low priority one. However, we don't want this reordering of updates to affect the terminal state. State should be deterministic: once all work has been flushed, the final state should be the same regardless of how they were scheduled. To get both properties, we store updates on the queue in insertion order instead of priority order (always append). Then, when processing the queue, we skip over updates with insufficient priority. Instead of removing updates from the queue right after processing them, we only remove them if there are no unprocessed updates before it in the list. This means that updates may be processed more than once. As a bonus, the new implementation is simpler and requires less code. * Fix ceiling function Mixed up the operators. * Remove addUpdate, addReplaceState, et al These functions don't really do anything. Simpler to use a single insertUpdateIntoFiber function. Also splits scheduleUpdate into two functions: - scheduleWork traverses a fiber's ancestor path and updates their expiration times. - scheduleUpdate inserts an update into a fiber's update queue, then calls scheduleWork. * Remove getExpirationTime The last remaining use for getExpirationTime was for top-level async updates. I moved that check to scheduleUpdate instead. * Move UpdateQueue insertions back to class module Moves UpdateQueue related functions out of the scheduler and back into the class component module. It's a bit awkward that now we need to pass around createUpdateExpirationForFiber, too. But we can still do without addUpdate, replaceUpdate, et al. * Store callbacks as an array of Updates Simpler this way. Also moves commitCallbacks back to UpdateQueue module. * beginUpdateQueue -> processUpdateQueue * Updates should never have an expiration of NoWork * Rename expiration related functions * Fix update queue Flow types Gets rid of an unneccessary null check
74 lines
2.1 KiB
JavaScript
74 lines
2.1 KiB
JavaScript
'use strict';
|
|
|
|
if (process.env.REACT_CLASS_EQUIVALENCE_TEST) {
|
|
// Inside the class equivalence tester, we have a custom environment, let's
|
|
// require that instead.
|
|
require('./setupSpecEquivalenceReporter.js');
|
|
} else {
|
|
var env = jasmine.getEnv();
|
|
|
|
// TODO: Stop using spyOn in all the test since that seem deprecated.
|
|
// This is a legacy upgrade path strategy from:
|
|
// https://github.com/facebook/jest/blob/v20.0.4/packages/jest-matchers/src/spyMatchers.js#L160
|
|
const isSpy = spy => spy.calls && typeof spy.calls.count === 'function';
|
|
|
|
['error', 'warn'].forEach(methodName => {
|
|
var oldMethod = console[methodName];
|
|
var newMethod = function() {
|
|
newMethod.__callCount++;
|
|
oldMethod.apply(this, arguments);
|
|
};
|
|
newMethod.__callCount = 0;
|
|
console[methodName] = newMethod;
|
|
|
|
env.beforeEach(() => {
|
|
newMethod.__callCount = 0;
|
|
});
|
|
|
|
env.afterEach(() => {
|
|
if (console[methodName] !== newMethod && !isSpy(console[methodName])) {
|
|
throw new Error(
|
|
'Test did not tear down console.' + methodName + ' mock properly.'
|
|
);
|
|
}
|
|
if (console[methodName].__callCount !== 0) {
|
|
throw new Error(
|
|
'Expected test not to call console.' +
|
|
methodName +
|
|
'(). ' +
|
|
'If the warning is expected, mock it out using ' +
|
|
"spyOn(console, '" +
|
|
methodName +
|
|
"') and test that the " +
|
|
'warning occurs.'
|
|
);
|
|
}
|
|
});
|
|
});
|
|
|
|
var wrapDevMatcher = function(obj, name) {
|
|
const original = obj[name];
|
|
obj[name] = function devMatcher() {
|
|
try {
|
|
original.apply(this, arguments);
|
|
} catch (e) {
|
|
global.__hadDevFailures = e.stack;
|
|
}
|
|
};
|
|
};
|
|
|
|
const expectDev = function expectDev(actual) {
|
|
const expectation = expect(actual);
|
|
if (global.__suppressDevFailures) {
|
|
Object.keys(expectation).forEach(name => {
|
|
wrapDevMatcher(expectation, name);
|
|
wrapDevMatcher(expectation.not, name);
|
|
});
|
|
}
|
|
return expectation;
|
|
};
|
|
global.expectDev = expectDev;
|
|
|
|
require('jasmine-check').install();
|
|
}
|