Best JavaScript code snippet using playwright-internal
4cb8b9d0ed5f067ca4dd9e921b4190df7c25aaReactChildFiber.js
Source:4cb8b9d0ed5f067ca4dd9e921b4190df7c25aaReactChildFiber.js
...173 return newFiber;174 }175 function updateTextNode(returnFiber, current, textContent, priority) {176 if (current === null || current.tag !== HostText) {177 var created = createFiberFromText(textContent, priority);178 created.return = returnFiber;179 return created;180 } else {181 var existing = useFiber(current, priority);182 existing.pendingProps = textContent;183 existing.return = returnFiber;184 return existing;185 }186 }187 function updateElement(returnFiber, current, element, priority) {188 if (current === null || current.type !== element.type) {189 var created = createFiberFromElement(element, priority);190 created.ref = coerceRef(current, element);191 created.return = returnFiber;192 return created;193 } else {194 var existing = useFiber(current, priority);195 existing.ref = coerceRef(current, element);196 existing.pendingProps = element.props;197 existing.return = returnFiber;198 if (__DEV__) {199 existing._debugSource = element._source;200 existing._debugOwner = element._owner;201 }202 return existing;203 }204 }205 function updateCoroutine(returnFiber, current, coroutine, priority) {206 if (current === null || current.tag !== CoroutineComponent) {207 var created = createFiberFromCoroutine(coroutine, priority);208 created.return = returnFiber;209 return created;210 } else {211 var existing = useFiber(current, priority);212 existing.pendingProps = coroutine;213 existing.return = returnFiber;214 return existing;215 }216 }217 function updateYield(returnFiber, current, yieldNode, priority) {218 if (current === null || current.tag !== YieldComponent) {219 var created = createFiberFromYield(yieldNode, priority);220 created.type = yieldNode.value;221 created.return = returnFiber;222 return created;223 } else {224 var existing = useFiber(current, priority);225 existing.type = yieldNode.value;226 existing.return = returnFiber;227 return existing;228 }229 }230 function updatePortal(returnFiber, current, portal, priority) {231 if (current === null || current.tag !== HostPortal || current.stateNode.containerInfo !== portal.containerInfo || current.stateNode.implementation !== portal.implementation) {232 var created = createFiberFromPortal(portal, priority);233 created.return = returnFiber;234 return created;235 } else {236 var existing = useFiber(current, priority);237 existing.pendingProps = portal.children || [];238 existing.return = returnFiber;239 return existing;240 }241 }242 function updateFragment(returnFiber, current, fragment, priority) {243 if (current === null || current.tag !== Fragment) {244 var created = createFiberFromFragment(fragment, priority);245 created.return = returnFiber;246 return created;247 } else {248 var existing = useFiber(current, priority);249 existing.pendingProps = fragment;250 existing.return = returnFiber;251 return existing;252 }253 }254 function createChild(returnFiber, newChild, priority) {255 if (typeof newChild === 'string' || typeof newChild === 'number') {256 var created = createFiberFromText('' + newChild, priority);257 created.return = returnFiber;258 return created;259 }260 if (typeof newChild === 'object' && newChild !== null) {261 switch (newChild.$$typeof) {262 case REACT_ELEMENT_TYPE:263 {264 var _created = createFiberFromElement(newChild, priority);265 _created.ref = coerceRef(null, newChild);266 _created.return = returnFiber;267 return _created;268 }269 case REACT_COROUTINE_TYPE:270 {271 var _created2 = createFiberFromCoroutine(newChild, priority);272 _created2.return = returnFiber;273 return _created2;274 }275 case REACT_YIELD_TYPE:276 {277 var _created3 = createFiberFromYield(newChild, priority);278 _created3.type = newChild.value;279 _created3.return = returnFiber;280 return _created3;281 }282 case REACT_PORTAL_TYPE:283 {284 var _created4 = createFiberFromPortal(newChild, priority);285 _created4.return = returnFiber;286 return _created4;287 }288 }289 if (isArray(newChild) || getIteratorFn(newChild)) {290 var _created5 = createFiberFromFragment(newChild, priority);291 _created5.return = returnFiber;292 return _created5;293 }294 throwOnInvalidObjectType(returnFiber, newChild);295 }296 return null;297 }298 function updateSlot(returnFiber, oldFiber, newChild, priority) {299 var key = oldFiber !== null ? oldFiber.key : null;300 if (typeof newChild === 'string' || typeof newChild === 'number') {301 if (key !== null) {302 return null;303 }304 return updateTextNode(returnFiber, oldFiber, '' + newChild, priority);305 }306 if (typeof newChild === 'object' && newChild !== null) {307 switch (newChild.$$typeof) {308 case REACT_ELEMENT_TYPE:309 {310 if (newChild.key === key) {311 return updateElement(returnFiber, oldFiber, newChild, priority);312 } else {313 return null;314 }315 }316 case REACT_COROUTINE_TYPE:317 {318 if (newChild.key === key) {319 return updateCoroutine(returnFiber, oldFiber, newChild, priority);320 } else {321 return null;322 }323 }324 case REACT_YIELD_TYPE:325 {326 if (key === null) {327 return updateYield(returnFiber, oldFiber, newChild, priority);328 } else {329 return null;330 }331 }332 case REACT_PORTAL_TYPE:333 {334 if (newChild.key === key) {335 return updatePortal(returnFiber, oldFiber, newChild, priority);336 } else {337 return null;338 }339 }340 }341 if (isArray(newChild) || getIteratorFn(newChild)) {342 if (key !== null) {343 return null;344 }345 return updateFragment(returnFiber, oldFiber, newChild, priority);346 }347 throwOnInvalidObjectType(returnFiber, newChild);348 }349 return null;350 }351 function updateFromMap(existingChildren, returnFiber, newIdx, newChild, priority) {352 if (typeof newChild === 'string' || typeof newChild === 'number') {353 var matchedFiber = existingChildren.get(newIdx) || null;354 return updateTextNode(returnFiber, matchedFiber, '' + newChild, priority);355 }356 if (typeof newChild === 'object' && newChild !== null) {357 switch (newChild.$$typeof) {358 case REACT_ELEMENT_TYPE:359 {360 var _matchedFiber = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;361 return updateElement(returnFiber, _matchedFiber, newChild, priority);362 }363 case REACT_COROUTINE_TYPE:364 {365 var _matchedFiber2 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;366 return updateCoroutine(returnFiber, _matchedFiber2, newChild, priority);367 }368 case REACT_YIELD_TYPE:369 {370 var _matchedFiber3 = existingChildren.get(newIdx) || null;371 return updateYield(returnFiber, _matchedFiber3, newChild, priority);372 }373 case REACT_PORTAL_TYPE:374 {375 var _matchedFiber4 = existingChildren.get(newChild.key === null ? newIdx : newChild.key) || null;376 return updatePortal(returnFiber, _matchedFiber4, newChild, priority);377 }378 }379 if (isArray(newChild) || getIteratorFn(newChild)) {380 var _matchedFiber5 = existingChildren.get(newIdx) || null;381 return updateFragment(returnFiber, _matchedFiber5, newChild, priority);382 }383 throwOnInvalidObjectType(returnFiber, newChild);384 }385 return null;386 }387 function warnOnDuplicateKey(child, knownKeys) {388 if (__DEV__) {389 if (typeof child !== 'object' || child === null) {390 return knownKeys;391 }392 switch (child.$$typeof) {393 case REACT_ELEMENT_TYPE:394 case REACT_COROUTINE_TYPE:395 case REACT_PORTAL_TYPE:396 var key = child.key;397 if (typeof key !== 'string') {398 break;399 }400 if (knownKeys === null) {401 knownKeys = new Set();402 knownKeys.add(key);403 break;404 }405 if (!knownKeys.has(key)) {406 knownKeys.add(key);407 break;408 }409 warning(false, 'Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, ' + 'only the first child will be used.%s', key, getCurrentFiberStackAddendum());410 break;411 default:412 break;413 }414 }415 return knownKeys;416 }417 function reconcileChildrenArray(returnFiber, currentFirstChild, newChildren, priority) {418 if (__DEV__) {419 var knownKeys = null;420 for (var i = 0; i < newChildren.length; i++) {421 var child = newChildren[i];422 knownKeys = warnOnDuplicateKey(child, knownKeys);423 }424 }425 var resultingFirstChild = null;426 var previousNewFiber = null;427 var oldFiber = currentFirstChild;428 var lastPlacedIndex = 0;429 var newIdx = 0;430 var nextOldFiber = null;431 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {432 if (oldFiber.index > newIdx) {433 nextOldFiber = oldFiber;434 oldFiber = null;435 } else {436 nextOldFiber = oldFiber.sibling;437 }438 var newFiber = updateSlot(returnFiber, oldFiber, newChildren[newIdx], priority);439 if (newFiber === null) {440 if (oldFiber === null) {441 oldFiber = nextOldFiber;442 }443 break;444 }445 if (shouldTrackSideEffects) {446 if (oldFiber && newFiber.alternate === null) {447 deleteChild(returnFiber, oldFiber);448 }449 }450 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);451 if (previousNewFiber === null) {452 resultingFirstChild = newFiber;453 } else {454 previousNewFiber.sibling = newFiber;455 }456 previousNewFiber = newFiber;457 oldFiber = nextOldFiber;458 }459 if (newIdx === newChildren.length) {460 deleteRemainingChildren(returnFiber, oldFiber);461 return resultingFirstChild;462 }463 if (oldFiber === null) {464 for (; newIdx < newChildren.length; newIdx++) {465 var _newFiber = createChild(returnFiber, newChildren[newIdx], priority);466 if (!_newFiber) {467 continue;468 }469 lastPlacedIndex = placeChild(_newFiber, lastPlacedIndex, newIdx);470 if (previousNewFiber === null) {471 resultingFirstChild = _newFiber;472 } else {473 previousNewFiber.sibling = _newFiber;474 }475 previousNewFiber = _newFiber;476 }477 return resultingFirstChild;478 }479 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);480 for (; newIdx < newChildren.length; newIdx++) {481 var _newFiber2 = updateFromMap(existingChildren, returnFiber, newIdx, newChildren[newIdx], priority);482 if (_newFiber2) {483 if (shouldTrackSideEffects) {484 if (_newFiber2.alternate !== null) {485 existingChildren.delete(_newFiber2.key === null ? newIdx : _newFiber2.key);486 }487 }488 lastPlacedIndex = placeChild(_newFiber2, lastPlacedIndex, newIdx);489 if (previousNewFiber === null) {490 resultingFirstChild = _newFiber2;491 } else {492 previousNewFiber.sibling = _newFiber2;493 }494 previousNewFiber = _newFiber2;495 }496 }497 if (shouldTrackSideEffects) {498 existingChildren.forEach(function (child) {499 return deleteChild(returnFiber, child);500 });501 }502 return resultingFirstChild;503 }504 function reconcileChildrenIterator(returnFiber, currentFirstChild, newChildrenIterable, priority) {505 var iteratorFn = getIteratorFn(newChildrenIterable);506 invariant(typeof iteratorFn === 'function', 'An object is not an iterable. This error is likely caused by a bug in ' + 'React. Please file an issue.');507 if (__DEV__) {508 if (typeof newChildrenIterable.entries === 'function') {509 var possibleMap = newChildrenIterable;510 if (possibleMap.entries === iteratorFn) {511 var mapsAsChildrenAddendum = '';512 var owner = ReactCurrentOwner.owner || returnFiber._debugOwner;513 if (owner && typeof owner.tag === 'number') {514 var mapsAsChildrenOwnerName = getComponentName(owner);515 if (mapsAsChildrenOwnerName) {516 mapsAsChildrenAddendum = '\n\nCheck the render method of `' + mapsAsChildrenOwnerName + '`.';517 }518 }519 warning(didWarnAboutMaps, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', mapsAsChildrenAddendum);520 didWarnAboutMaps = true;521 }522 }523 var _newChildren = iteratorFn.call(newChildrenIterable);524 if (_newChildren) {525 var knownKeys = null;526 var _step = _newChildren.next();527 for (; !_step.done; _step = _newChildren.next()) {528 var child = _step.value;529 knownKeys = warnOnDuplicateKey(child, knownKeys);530 }531 }532 }533 var newChildren = iteratorFn.call(newChildrenIterable);534 invariant(newChildren != null, 'An iterable object provided no iterator.');535 var resultingFirstChild = null;536 var previousNewFiber = null;537 var oldFiber = currentFirstChild;538 var lastPlacedIndex = 0;539 var newIdx = 0;540 var nextOldFiber = null;541 var step = newChildren.next();542 for (; oldFiber !== null && !step.done; newIdx++, step = newChildren.next()) {543 if (oldFiber.index > newIdx) {544 nextOldFiber = oldFiber;545 oldFiber = null;546 } else {547 nextOldFiber = oldFiber.sibling;548 }549 var newFiber = updateSlot(returnFiber, oldFiber, step.value, priority);550 if (newFiber === null) {551 if (!oldFiber) {552 oldFiber = nextOldFiber;553 }554 break;555 }556 if (shouldTrackSideEffects) {557 if (oldFiber && newFiber.alternate === null) {558 deleteChild(returnFiber, oldFiber);559 }560 }561 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);562 if (previousNewFiber === null) {563 resultingFirstChild = newFiber;564 } else {565 previousNewFiber.sibling = newFiber;566 }567 previousNewFiber = newFiber;568 oldFiber = nextOldFiber;569 }570 if (step.done) {571 deleteRemainingChildren(returnFiber, oldFiber);572 return resultingFirstChild;573 }574 if (oldFiber === null) {575 for (; !step.done; newIdx++, step = newChildren.next()) {576 var _newFiber3 = createChild(returnFiber, step.value, priority);577 if (_newFiber3 === null) {578 continue;579 }580 lastPlacedIndex = placeChild(_newFiber3, lastPlacedIndex, newIdx);581 if (previousNewFiber === null) {582 resultingFirstChild = _newFiber3;583 } else {584 previousNewFiber.sibling = _newFiber3;585 }586 previousNewFiber = _newFiber3;587 }588 return resultingFirstChild;589 }590 var existingChildren = mapRemainingChildren(returnFiber, oldFiber);591 for (; !step.done; newIdx++, step = newChildren.next()) {592 var _newFiber4 = updateFromMap(existingChildren, returnFiber, newIdx, step.value, priority);593 if (_newFiber4 !== null) {594 if (shouldTrackSideEffects) {595 if (_newFiber4.alternate !== null) {596 existingChildren.delete(_newFiber4.key === null ? newIdx : _newFiber4.key);597 }598 }599 lastPlacedIndex = placeChild(_newFiber4, lastPlacedIndex, newIdx);600 if (previousNewFiber === null) {601 resultingFirstChild = _newFiber4;602 } else {603 previousNewFiber.sibling = _newFiber4;604 }605 previousNewFiber = _newFiber4;606 }607 }608 if (shouldTrackSideEffects) {609 existingChildren.forEach(function (child) {610 return deleteChild(returnFiber, child);611 });612 }613 return resultingFirstChild;614 }615 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent, priority) {616 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {617 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);618 var existing = useFiber(currentFirstChild, priority);619 existing.pendingProps = textContent;620 existing.return = returnFiber;621 return existing;622 }623 deleteRemainingChildren(returnFiber, currentFirstChild);624 var created = createFiberFromText(textContent, priority);625 created.return = returnFiber;626 return created;627 }628 function reconcileSingleElement(returnFiber, currentFirstChild, element, priority) {629 var key = element.key;630 var child = currentFirstChild;631 while (child !== null) {632 if (child.key === key) {633 if (child.type === element.type) {634 deleteRemainingChildren(returnFiber, child.sibling);635 var existing = useFiber(child, priority);636 existing.ref = coerceRef(child, element);637 existing.pendingProps = element.props;638 existing.return = returnFiber;...
react-diff.js
Source:react-diff.js
...47 existing.return = returnFiber;48 return existing;49 }50 deleteRemainingChildren(returnFiber, currentFirstChild);51 const created = createFiberFromText(textConent, returnFiber.mode);52 created.return = returnFiber;53 return created;54}55function placeChild(newFiber, lastPlacedIndex, newIdx) {56 newFiber.index = newIndex;57 if (!shouldTrackSideEffects) {58 return lastPlacedIndex;59 }60 const current = newFiber.alternate; // current== null,该èç¹ä¸ºæ°å¢èç¹61 if (current !== null) {62 // current !== null 表示æ´æ°ï¼åå¨å·²æèç¹63 const oldIndex = current.index;64 if (oldIndex < lastPlacedIndex) {65 newFiber.flags = Placement;66 return lastPlacedIndex;67 } else {68 // 该项ä¾ç¶çå¨èä½ç½®69 return oldIndex;70 }71 } else {72 newFiber.flags = Placement;73 return lastPlacedIndex;74 }75}76function updateTextNode(returnFiber, current, textContent) {77 // currentèç¹ä¸æ¯å¯å¤ç¨çææ¬èç¹78 if (current === null || current.tag !== HostText) {79 // éè¿textContentå建ææ¬èç¹Fiber80 const created = createFiberFromText(textContent, returnFiber.mode);81 created.return = returnFiber;82 return created;83 } else {84 // æ¾å°å¯å¤ç¨çææ¬èç¹äºï¼åå¤ç¨85 const existing = useFiber(current, textContent); // å¤ç¨ææ¬èç¹86 existing.return = returnFiber;87 return existing;88 }89}90function updateElement(returnFiber, current, element) {91 if (current !== null) {92 if (current.elementType === element.type) {93 const existing = useFiber(current, element.props); // å¤ç¨èç¹94 existing.ref = coerceRef(returnFiber, current, element);95 existing.return = returnFiber;96 return existing;97 }98 }99 // æ°èç¹100 const created = createFiberFromElement(element, returnFiber.mode);101 created.ref = coerceRef(returnFiber, current, element);102 created.return = returnFiber;103 return created;104}105// å°ææèèç¹æ·»å å°Map对象ä¸106function mapRemainingChildren(returnFiber, currentFirstChild) {107 const existingChildren = new Map();108 let existingChild = currentFirstChild;109 while (existingChild !== null) {110 // key ä¸ä¸ºnull å
ç´ èç¹111 if (existingChild.key !== null) {112 existingChildren.set(existingChild.key, existingChild);113 } else {114 // ä¸åå¨key å使ç¨index代æ¿115 existingChildren.set(existingChild.index, existingChild);116 }117 existingChild = existingChild.sibling;118 }119 return existingChildren;120}121function updateFromMap(existingChildren, returnFiber, newIdx, newChild) {122 // æ°èç¹æ¯ææ¬èç¹123 if (typeof newChild === 'string' || typeof newChild === 'number') {124 const matchedFiber = existingChildren.get(newIdx) || null; // æ¾indexç¸åçèç¹å¤ç¨125 return updateTextNode(returnFiber, matchedFiber, '' + newChild);126 }127 // newChildæ¯å
ç´ èç¹çæ
åµ128 if (typeof newChild === 'object' && newChild !== null) {129 if (newChild.$$typeof === REACT_ELEMENT_TYPE) {130 const matchedFiber =131 existingChildren.get(newChild.key ? newChild.key : newChild.index) ||132 null;133 // è¿åæ´æ°åçå
ç´ èç¹134 return updateElement(returnFiber, matchedFiber, newChild);135 }136 }137 return null;138}139function createChild(returnFiber, newChild) {140 // å¤çææ¬èç¹141 if (typeof newChild === 'string' || typeof newChild === 'number') {142 const created = createFiberFromText('' + newChild, returnFiber.mode);143 created.return = returnFiber;144 return created;145 }146 // å¤çå
ç´ èç¹147 if (typeof newChild === 'object' && newChild !== null) {148 if (newChild.$$typeof === REACT_ELEMENT_TYPE) {149 const created = createFiberFromElement(newChild, returnFiber.mode);150 created.ref = coerceRef(returnFiber, null, newChild);151 created.return = returnFiber;152 return created;153 }154 }155 return null;156}157function createFiberFromText(content, mode) {158 const fiber = createFiber(HostText, content, null);159 return fiber;160}161function createFiberFromElement(element, mode) {162 let owner = null;163 const type = element.type;164 const key = element.key;165 const pendingProps = element.props;166 const fiber = createFiberFromTypeAndProps(167 type,168 key,169 pendingProps,170 owner,171 mode...
childFiber.js
Source:childFiber.js
...50 return null;51 }52 function updateTextNode(returnFiber, current, textContent, expirationTime) {53 if (current === null || current.tag !== HostText) {54 const created = createFiberFromText(55 textContent,56 returnFiber.mode,57 expirationTime,58 );59 created.return = returnFiber;60 return created;61 } else {62 // update63 const existing = useFiber(current, textContent, expirationTime);64 existing.return = returnFiber;65 return existing;66 }67 }68 function updateElement(returnFiber, current, element, expirationTime) {69 if (current !== null && current.elementType === element.type) {70 // type ç¸å71 const existing = useFiber(current, element.props, expirationTime);72 existing.ref = coerceRef(returnFiber, current, element);73 existing.return = returnFiber;74 return existing;75 } else {76 const created = createFiberFromElement(77 element,78 returnFiber.mode,79 expirationTime,80 );81 created.return = returnFiber;82 return created;83 }84 }85 function updateSlot(returnFiber, oldFiber, newChild, expirationTime) {86 const key = oldFiber !== null ? oldFiber.key : null;87 if (typeof newChild === 'string' || typeof newChild === 'number') {88 if (key !== null) {89 return null;90 }91 return updateTextNode(92 returnFiber,93 oldFiber,94 '' + newChild,95 expirationTime,96 );97 }98 if (typeof newChild === 'object' && newChild !== null) {99 switch (newChild.$$typeof) {100 case REACT_ELEMENT_TYPE: {101 if (newChild.key === key) {102 if (newChild.type === REACT_FRAGMENT_TYPE) {103 // todo104 return null;105 }106 return updateElement(107 returnFiber,108 oldFiber,109 newChild,110 expirationTime,111 );112 }113 }114 }115 }116 }117 function useFiber(fiber, pendingProps, expirationTime) {118 // We currently set sibling to null and index to 0 here because it is easy119 // to forget to do before returning it. E.g. for the single child case.120 121 // éç¨ä¹åçfiber æ´æ° props å è¿ææ¶é´122 const clone = createWorkInProgress(fiber, pendingProps, expirationTime);123 clone.index = 0;124 clone.sibling = null;125 return clone;126 }127 function createChild(returnFiber, newChild, expirationTime) {128 //129 if (typeof newChild === 'string' || typeof newChild === 'number') {130 const created = createFiberFromText(131 '' + newChild,132 returnFiber.mode,133 expirationTime,134 );135 created.return = returnFiber;136 return created;137 }138 if ((typeof newChild === 'object') !== null) {139 switch (newChild.$$typeof) {140 case REACT_ELEMENT_TYPE: {141 const created = createFiberFromElement(142 newChild,143 returnFiber.mode,144 expirationTime,145 );146 created.ref = coerceRef(returnFiber, null, newChild);147 created.return = returnFiber;148 return created;149 }150 }151 // TODO152 // if (isArray(newChild) || getIteratorFn(newChild)) {153 if (isArray(newChild)) {154 const created = createFiberFromFragment(155 newChild,156 returnFiber.mode,157 expirationTime,158 null,159 );160 created.return = returnFiber;161 return created;162 }163 }164 return null;165 }166 function placeChild(newFiber, lastPlacedIndex, newIndex) {167 newFiber.index = newIndex;168 if (!shouldTrackSideEffects) {169 return lastPlacedIndex;170 }171 // TODO172 const current = newFiber.alternate;173 if (current !== null) {174 }175 }176 function placeSingleChild(fiber) {177 if (shouldTrackSideEffects && fiber.alternate === null) {178 fiber.effectTag |= Placement;179 }180 return fiber;181 }182 function reconcileChildrenArray(183 returnFiber,184 currentFirstChild,185 newChildren,186 expirationTime,187 ) {188 let resultingFirstChild = null;189 let previousNewFiber = null;190 let oldFiber = currentFirstChild;191 let lastPlacedIndex = 0;192 let newIdx = 0;193 let nextOldFiber = null;194 for (; oldFiber !== null && newIdx < newChildren.length; newIdx++) {195 // TODO 第ä¸æ¸²æ oldFiber为null196 if (oldFiber.index > newIdx) {197 nextOldFiber = oldFiber;198 oldFiber = null;199 } else {200 nextOldFiber = oldFiber.sibling;201 }202 const newFiber = updateSlot(203 returnFiber,204 oldFiber,205 newChildren[newIdx],206 expirationTime,207 );208 if (newFiber === null) {209 if (oldFiber === null) {210 oldFiber = nextOldFiber211 }212 break213 }214 if (shouldTrackSideEffects) {215 if (oldFiber && newFiber.alternate === null) {216 // ä¸è½éç¨ç æ è®°å é¤217 deleteChild(returnFiber, oldFiber)218 }219 }220 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx)221 if (previousNewFiber === null) {222 resultingFirstChild = newFiber223 } else {224 previousNewFiber.sibling = newFiber225 }226 previousNewFiber = newFiber227 oldFiber = nextOldFiber228 }229 if (newIdx === newChildren.length) {230 // å·²ç»éåå®æ¯ é½å¯ä»¥éç¨ æ è®°éè¦å é¤ç没人231 deleteRemainingChildren(returnFiber, oldFiber);232 return resultingFirstChild;233 }234 if (oldFiber === null) {235 for (; newIdx < newChildren.length; newIdx++) {236 const newFiber = createChild(237 returnFiber,238 newChildren[newIdx],239 expirationTime,240 );241 if (newFiber === null) {242 continue;243 }244 lastPlacedIndex = placeChild(newFiber, lastPlacedIndex, newIdx);245 if (previousNewFiber === null) {246 resultingFirstChild = newFiber;247 } else {248 previousNewFiber.sibling = newFiber;249 }250 previousNewFiber = newFiber;251 }252 return resultingFirstChild;253 }254 }255 function reconcileSingleTextNode(256 returnFiber,257 currentFirstChild,258 textContent,259 expirationTime,260 ) {261 if (currentFirstChild !== null && currentFirstChild.tag === HostText) {262 deleteRemainingChildren(returnFiber, currentFirstChild.sibling);263 const existing = useFiber(264 currentFirstChild,265 textContent,266 expirationTime,267 );268 existing.return = returnFiber;269 return existing;270 }271 // å·²åå¨ç第ä¸ä¸ªchildèç¹ ä¸æ¯ä¸ä¸ªtextèç¹ æ以æ们éè¦å建ä¸ä¸ªæ°ç å é¤æ§ç272 deleteRemainingChildren(returnFiber, currentFirstChild);273 const created = createFiberFromText(274 textContent,275 returnFiber.mode,276 expirationTime,277 );278 created.return = returnFiber;279 return created;280 }281 function reconcileSingleElement(282 returnFiber,283 currentFirstChild,284 element,285 expirationTime,286 ) {287 const key = element.key;...
ReactFiber.js
Source:ReactFiber.js
...81 lanes82 );83 return fiber;84}85function createFiberFromText(content, mode, lanes) {86 const fiber = createFiber(HostText, content, null, mode);87 fiber.lanes = lanes;88 return fiber;89}90function createWorkInProgress(current, pendingProps) {91 let workInProgress = current.alternate;92 if(workInProgress === null) {93 // æ å½åè¿ç¨fiberæ¶ç´æ¥å建94 workInProgress = createFiber(95 current.tag,96 pendingProps,97 current.key,98 current.mode99 );...
ReactChildFiber.js
Source:ReactChildFiber.js
...13 // å½ shouldTrackSideEffects 为falseæ¶ è¡¨ç¤ºå次mount,åªéè¦å¨ æ ¹èç¹ä¸æä¸ effectæ è®°ï¼å
¶ä»èç¹ä¸éè¦æeffectæ è®°14 // å½ shouldTrackSideEffects 为trueæ¶ï¼è¡¨ç¤ºæ´æ°ï¼ä¼å¨æ¯ä¸ªéè¦updateçèç¹ä¸æä¸ effect æ è®°15 function createChild(returnFiber, newChild) {16 if (typeof newChild === 'number' || typeof newChild === 'string') {17 const created = createFiberFromText(newChild);18 created.return = returnFiber;19 return created;20 }21 if (typeof newChild === 'object' && newChild !== null) {22 if (newChild.$$typeof === REACT_ELEMENT_TYPE) {23 const created = createFiberFromElement(newChild);24 created.return = returnFiber;25 return created;26 }27 }28 return null;29 }30 // åè°åfiber å建fiber31 function reconcileSingleElement(returnFiber, currentFirstChild, element) {32 // key diff ç®æ³å¾
è¡¥å
33 // 为å
ç´ å建 fiber34 const created = createFiberFromElement(element);35 // æ·»å å½åfiberçç¶çº§ fiber36 created.return = returnFiber;37 return created;38 }39 // ææ¬èç¹40 function reconcileSingleTextNode(returnFiber, currentFirstChild, textContent) {41 // çç¥æ´æ°è¿ç¨42 // 为ææ¬èç¹å建fiberèç¹43 const created = createFiberFromText(textContent);44 // return 表示ææ¬èç¹çç¶èç¹45 created.return = returnFiber;46 return created;47 }48 // æ å¿å½åfiberéè¦å¨commité¶æ®µæå
¥DOM49 function placeSingleChild(fiber) {50 // shouldTrackSideEffects 为true表示 æ´æ°51 // alternate ä¸åå¨ï¼è¡¨ç¤ºæ°å¢çèç¹52 // alternate åå¨ï¼è¡¨ç¤ºéè¦æ´æ°çèç¹53 if (shouldTrackSideEffects && !fiber.alternate) {54 // 为fiberèç¹æä¸ æ´æ° effectæ è®°55 fiber.effectTag = Placement;56 }57 return fiber;...
benginWork.js
Source:benginWork.js
...118 returnFiber,119 newChild120) {121 if (typeof newChild === 'string' || typeof newChild === 'number') {122 const created = createFiberFromText('' + newChild)123 return created124 }125 return null126}127function placeSingleChild(newFiber) {128 return newFiber129}130function reconcileSingleTextNode(131 returnFiber,132 currentFirstChild,133 textContent134) {135 deleteRemainingChildren(returnFiber, currentFirstChild)136 const created = createFiberFromText(textContent)137 return created138}139function deleteChild(returnFiber, childToDelete) {140 const deletions = returnFiber.deletions141 if (deletions !== null) {142 returnFiber.deletions = [childToDelete]143 returnFiber.flags |= 'Deletion'144 } else {145 deletions.push(childToDelete)146 }147}148function deleteRemainingChildren(returnFiber, currentFirstChild) {149 let childToDelete = currentFirstChild150 while(childToDelete !== null) {151 deleteChild(returnFiber, childToDelete)152 childToDelete = childToDelete.sibling153 }154 return null155}156function createFiberFromText( content) {157 const fiber = creatFiber(FiberTag.HostText, content, null)158 return fiber159}160function creatFiber( tag, pendingProps, key) {161 return new FiberNode(tag, pendingProps, key)162}163function FiberNode(164 tag,165 pendingProps,166 key167) {168 this.tag = tag169 this.key = key170 this.elementType = null...
index.js
Source:index.js
1//@flow2import React from 'react'3import ReactDOM from 'react-dom'4import Reconciler from 'react-reconciler'5import emptyObject from 'fbjs/lib/emptyObject';6import * as Scheduler from 'scheduler/unstable_mock';7import CustomRenderer from './reglbase'8// import {9// createWorkInProgress,10// createFiberFromElement,11// createFiberFromFragment,12// createFiberFromText,13// createFiberFromPortal,14// } from 'react-reconciler';15class App extends React.Component {16 constructor(){17 super()18 this.state = { count: Math.random() }19 }20 // shouldComponentUpdate(){21 // console.log('shodul i update')22 // return true23 // }24 render(){25 // console.log(this)26 let num = this.state.count.toFixed(2);27 console.log(num)28 return <div>29 30 <p>hello world</p>31 <button onClick={e => this.setState({ count: 1 + this.state.count })}>32 Clicked <Thing>{num}</Thing> times33 </button>34 </div>35 }36}37function Thing(props){38 React.useEffect(() => {39 debugger40 console.log('hello')41 })42 console.log('thing', props.children)43 return <div>{props.children}</div>44}45console.log(CustomRenderer)46var element = <App />47// ReactDOM.render(element, document.getElementById('root'))48// render(<App />, { stuff: [] })49// var internalRoot = document.getElementById('root')._reactRootContainer._internalRoot50// console.log(internalRoot)51// setTimeout(() => {52// const customContainer = CustomRenderer.createContainer({});53// customContainer.current = cloneFiber(internalRoot.current);54// console.log(customContainer, 'cc')55// debugger56// CustomRenderer.updateContainer(<App xyz />, customContainer, null);57let customContainer = CustomRenderer.createContainer({});58CustomRenderer.updateContainer(<App />, customContainer, null)59CustomRenderer.updateContainer(<App />, customContainer, null)60// CustomRenderer.updateContainer(<App />, customContainer, null)61// CustomRenderer.updateContainer(<App />, customContainer, null)62console.log(customContainer)63function cloneFiber(fiber, map = new Map()){64 if(!fiber) return fiber;65 if(map.has(fiber)) return map.get(fiber);66 let clone = { ...fiber }67 map.set(fiber, clone)68 if(clone.stateNode){69 clone.stateNode = {70 containerInfo: {}71 }72 }73 clone.child = cloneFiber(fiber.child, map)74 clone.sibling = cloneFiber(fiber.sibling, map)75 clone.return = cloneFiber(fiber.return, map)76 77 return clone;78}79// }, 100)80// function metaproxy(obj){81// return new Proxy(obj, {82// get(target, prop, receiver){83// let value = Reflect.get(target, prop, receiver)84// if(value && typeof value == 'object'){85// console.log('getting', prop, value)86// return metaproxy(value)87// }88// return value;89// // console.log(prop, receiver, Reflect.get(...arguments))90// // return Reflect.get(...arguments);91// }92// })93// }94// var p = metaproxy(internalRoot);95// // 96// CustomRenderer.updateContainer(<App two />, p, null);97// setTimeout(function(args) {98// CustomRenderer.updateContainer(element, internalRoot, null);99// }, 1000)...
Diff-TextNode.js
Source:Diff-TextNode.js
...39 å¨æºç é useFiber å°±æ¯å¤ç¨èç¹çæ¹æ³ï¼deleteRemainingChildren å°±æ¯å é¤å©ä½èç¹çæ¹æ³ï¼è¿éæ¯ä» currentFirstChild.sibling å¼å§å é¤çã40 第äºç§æ
åµãxxx ä¸æ¯ä¸ä¸ª TextNodeï¼é£ä¹å°±ä»£è¡¨è¿ä¸ªèç¹ä¸è½å¤ç¨ï¼æ以就ä»currentFirstChildå¼å§å æå©ä½çèç¹ï¼å¯¹åºå°ä¸é¢çå¾ä¸å°±æ¯å é¤æ xxx èç¹å aaa èç¹ã41 对äºæºç å¦ä¸ï¼42 deleteRemainingChildren(returnFiber, currentFirstChild);43 const created = createFiberFromText(44 textContent,45 returnFiber.mode,46 expirationTime,47 );48 created.return = returnFiber;49 å
¶ä¸ createFiberFromText å°±æ¯æ ¹æ® textContent æ¥å建èç¹çæ¹æ³ã...
Using AI Code Generation
1import { createFiberFromText } from "playwright/lib/server/dom/fiber.js";2const fiber = createFiberFromText("Hello World");3console.log(fiber);4import { createFiberFromElement } from "playwright/lib/server/dom/fiber.js";5const fiber = createFiberFromElement("div");6console.log(fiber);7const fiber = createFiberFromText("Hello World");8console.log(fiber);9const fiber = createFiberFromElement("div");10console.log(fiber);
Using AI Code Generation
1const {createFiberFromText} = require('playwright/lib/server/dom.js');2const fiber = createFiberFromText('text', document);3console.log(fiber);4const {createFiberFromText} = require('playwright/lib/server/dom.js');5const fiber = createFiberFromText('text', document);6console.log(fiber);7const {createFiberFromText} = require('playwright/lib/server/dom.js');8const fiber = createFiberFromText('text', document);9console.log(fiber);10const {createFiberFromText} = require('playwright/lib/server/dom.js');11const fiber = createFiberFromText('text', document);12console.log(fiber);13const {createFiberFromText} = require('playwright/lib/server/dom.js');14const fiber = createFiberFromText('text', document);15console.log(fiber);16const {createFiberFromText} = require('playwright/lib/server/dom.js');17const fiber = createFiberFromText('text', document);18console.log(fiber);19const {createFiberFromText} = require('playwright/lib/server/dom.js');
Using AI Code Generation
1var {createFiberFromText} = require('playwright/lib/webkit/wkPage');2var fiber = createFiberFromText('Hello World');3fiber.evaluate(() => {4 console.log('Hello World');5});6{7 "dependencies": {8 }9}
Using AI Code Generation
1import { createFiberFromText } from 'playwright/lib/server/dom.js';2const fiber = createFiberFromText('test');3console.log(fiber);4{ _debugID: 0,5 alternate: null }6The output is a bit big but the important thing is to note that the type is test . This is what we need to pass to the render method of ReactDOM7ReactDOM.render(8 document.getElementById('root'),9);10import { createFiberFromText } from 'playwright/lib/server/dom.js';11import ReactDOM from 'react-dom';12const fiber = createFiberFromText('test');13ReactDOM.render(14 document.getElementById('root'),15);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!