Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
atellmer committed Aug 25, 2023
1 parent e17bf23 commit 885075b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/fiber/fiber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { detectIsFunction } from '../helpers';
import { wipRootStore, isUpdateHookZone } from '../scope';
import { detectIsTagVirtualNode, detectIsPlainVirtualNode } from '../view';
import type { Context, ContextProviderValue } from '../context';
import type { DarkElementInstance } from '../shared';
import type { DarkElementInstance, DarkElementKey } from '../shared';
import { type NativeElement, type Hook, EffectTag } from './types';

class Fiber<N = NativeElement> {
Expand All @@ -26,7 +26,7 @@ class Fiber<N = NativeElement> {
public iefHost: boolean; // insertion effect host
public aHost: boolean; // atom host
public pHost: boolean; // portal host
public marker: string; // for dev
public marker: DarkElementKey; // for dev
public used: boolean; // flag if fiber already been rendered
public shadow: boolean; // flag for shadow rendering
public batch: number | NodeJS.Timeout | null; // timer for batching
Expand Down
48 changes: 19 additions & 29 deletions packages/core/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const detectIsNull = (o: any): o is null => o === null;

const detectIsEmpty = (o: any) => detectIsNull(o) || detectIsUndefined(o);

const detectIsFalsy = (o: any) => detectIsNull(o) || detectIsUndefined(o) || o === false;
const detectIsFalsy = (o: any) => detectIsEmpty(o) || o === false;

const getTime = () => Date.now();

Expand All @@ -31,37 +31,27 @@ function error(...args: Array<any>) {
}

function flatten<T = any>(source: Array<NestedArray<T>>): Array<T> {
const list = [];
const levelMap = { 0: { idx: 0, source } };
let level = 0;

do {
const { source, idx } = levelMap[level];
const item = source[idx];

if (idx >= source.length) {
level--;
if (!levelMap[level]) {
levelMap[level] = {
idx: 0,
source: [],
};
}
levelMap[level].idx++;
continue;
}
if (source.length === 0) return [];
const list: Array<T> = [];
const stack = [source[0]];
let idx = 0;

if (detectIsArray(item)) {
level++;
levelMap[level] = {
idx: 0,
source: item,
};
while (stack.length > 0) {
const x = stack.pop();

if (detectIsArray(x)) {
for (let i = x.length - 1; i >= 0; i--) {
stack.push(x[i]);
}
} else {
list.push(item);
levelMap[level].idx++;
list.push(x);

if (stack.length === 0 && idx < source.length - 1) {
idx++;
stack.push(source[idx]);
}
}
} while (level > 0 || levelMap[level].idx < levelMap[level].source.length);
}

return list;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/workloop/workloop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function createConditionalFiber(alternate: Fiber, marker?: DarkElementKey) {
tag: EffectTag.C,
inst: createReplacer(),
parent: alternate,
marker: marker + '',
marker,
});
}

Expand Down

0 comments on commit 885075b

Please sign in to comment.