Skip to content

Commit 83e9cc5

Browse files
committed
Remove queue implementation for dirty components
Found a way to make it work without changing the dirty components array into a queue structure, reducing bundle size.
1 parent 96ddf85 commit 83e9cc5

File tree

2 files changed

+7
-38
lines changed

2 files changed

+7
-38
lines changed

src/runtime/internal/scheduler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { run_all, Queue } from './utils';
1+
import { run_all } from './utils';
22
import { get_current_component, set_current_component } from './lifecycle';
33

4-
export const dirty_components = new Queue<any>();
4+
export const dirty_components = [];
55
export const intros = { enabled: false };
66

77
export const binding_callbacks = [];
@@ -32,6 +32,7 @@ export function add_flush_callback(fn) {
3232
}
3333

3434
const seen_callbacks = new Set();
35+
let flushidx = 0; // Do *not* move this inside the flush() function
3536
export function flush() {
3637

3738
let current_component = null;
@@ -44,14 +45,16 @@ export function flush() {
4445
do {
4546
// first, call beforeUpdate functions
4647
// and update components
47-
while (dirty_components.length) {
48-
const component = dirty_components.shift();
48+
while (flushidx < dirty_components.length) {
49+
const component = dirty_components[flushidx];
50+
flushidx++;
4951
set_current_component(component);
5052
update(component.$$);
5153
}
5254
set_current_component(null);
5355

5456
dirty_components.length = 0;
57+
flushidx = 0;
5558

5659
while (binding_callbacks.length) binding_callbacks.pop()();
5760

src/runtime/internal/utils.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,40 +58,6 @@ export function is_empty(obj) {
5858
return Object.keys(obj).length === 0;
5959
}
6060

61-
export class Queue<T> {
62-
forward: T[];
63-
reverse: T[];
64-
65-
constructor() {
66-
this.forward = [];
67-
this.reverse = [];
68-
}
69-
push(value: T) {
70-
return this.forward.push(value);
71-
}
72-
shift() {
73-
if (this.reverse.length === 0) {
74-
while (this.forward.length) {
75-
this.reverse.push(this.forward.pop());
76-
}
77-
}
78-
return this.reverse.pop();
79-
}
80-
get length() {
81-
return this.forward.length + this.reverse.length;
82-
}
83-
set length(len: number) {
84-
if (len === 0) {
85-
this.forward.length = 0;
86-
this.reverse.length = 0;
87-
} else {
88-
while (this.length > len) {
89-
this.shift();
90-
}
91-
}
92-
}
93-
}
94-
9561
export function validate_store(store, name) {
9662
if (store != null && typeof store.subscribe !== 'function') {
9763
throw new Error(`'${name}' is not a store with a 'subscribe' method`);

0 commit comments

Comments
 (0)