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.
pull/6920/head
Robin Munn 5 years ago
parent 96ddf85521
commit 83e9cc5d5d

@ -1,7 +1,7 @@
import { run_all, Queue } from './utils';
import { run_all } from './utils';
import { get_current_component, set_current_component } from './lifecycle';
export const dirty_components = new Queue<any>();
export const dirty_components = [];
export const intros = { enabled: false };
export const binding_callbacks = [];
@ -32,6 +32,7 @@ export function add_flush_callback(fn) {
}
const seen_callbacks = new Set();
let flushidx = 0; // Do *not* move this inside the flush() function
export function flush() {
let current_component = null;
@ -44,14 +45,16 @@ export function flush() {
do {
// first, call beforeUpdate functions
// and update components
while (dirty_components.length) {
const component = dirty_components.shift();
while (flushidx < dirty_components.length) {
const component = dirty_components[flushidx];
flushidx++;
set_current_component(component);
update(component.$$);
}
set_current_component(null);
dirty_components.length = 0;
flushidx = 0;
while (binding_callbacks.length) binding_callbacks.pop()();

@ -58,40 +58,6 @@ export function is_empty(obj) {
return Object.keys(obj).length === 0;
}
export class Queue<T> {
forward: T[];
reverse: T[];
constructor() {
this.forward = [];
this.reverse = [];
}
push(value: T) {
return this.forward.push(value);
}
shift() {
if (this.reverse.length === 0) {
while (this.forward.length) {
this.reverse.push(this.forward.pop());
}
}
return this.reverse.pop();
}
get length() {
return this.forward.length + this.reverse.length;
}
set length(len: number) {
if (len === 0) {
this.forward.length = 0;
this.reverse.length = 0;
} else {
while (this.length > len) {
this.shift();
}
}
}
}
export function validate_store(store, name) {
if (store != null && typeof store.subscribe !== 'function') {
throw new Error(`'${name}' is not a store with a 'subscribe' method`);

Loading…
Cancel
Save