improve output size by destructuring $$

pull/5702/head
Ivan Hofer 5 years ago
parent febaea9bc4
commit 463e25770a

@ -36,11 +36,11 @@ interface T$$ {
skip_bound: boolean;
}
export function bind(component, name, callback) {
const index = component.$$.props[name];
export function bind({ $$ }, name, callback) {
const index = $$.props[name];
if (index !== undefined) {
component.$$.bound[index] = callback;
callback(component.$$.ctx[index]);
$$.bound[index] = callback;
callback($$.ctx[index]);
}
}
@ -52,8 +52,8 @@ export function claim_component(block, parent_nodes) {
block && block.l(parent_nodes);
}
export function mount_component(component, target, anchor) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
export function mount_component({ $$ }, target, anchor) {
const { fragment, on_mount, on_destroy, after_update } = $$;
fragment && fragment.m(target, anchor);
@ -67,18 +67,18 @@ export function mount_component(component, target, anchor) {
// most likely as a result of a binding initialising
run_all(new_on_destroy);
}
component.$$.on_mount = [];
$$.on_mount = [];
});
after_update.forEach(add_render_callback);
}
export function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
export function destroy_component({ $$ }, detaching) {
const { fragment } = $$;
if (fragment !== null) {
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
fragment && fragment.d(detaching);
// TODO null out other refs, including component.$$ (but need to
// preserve final state?)
@ -88,12 +88,13 @@ export function destroy_component(component, detaching) {
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
const { $$ } = component;
if ($$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
$$.dirty.fill(0);
}
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}
export function init(component, options, instance, create_fragment, not_equal, props, dirty = [-1]) {
@ -146,17 +147,19 @@ export function init(component, options, instance, create_fragment, not_equal, p
$$.fragment = create_fragment ? create_fragment($$.ctx) : false;
if (options.target) {
const { fragment } = $$;
if (options.hydrate) {
const nodes = children(options.target);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment!.l(nodes);
fragment && fragment!.l(nodes);
nodes.forEach(detach);
} else {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
$$.fragment && $$.fragment!.c();
fragment && fragment!.c();
}
if (options.intro) transition_in(component.$$.fragment);
if (options.intro) transition_in(fragment);
mount_component(component, options.target, options.anchor);
flush();
}
@ -193,7 +196,8 @@ if (typeof HTMLElement === 'function') {
$on(type, callback) {
// TODO should this delegate to addEventListener?
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
const { $$ } = this;
const callbacks = ($$.callbacks[type] || ($$.callbacks[type] = []));
callbacks.push(callback);
return () => {
@ -203,10 +207,11 @@ if (typeof HTMLElement === 'function') {
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
const { $$set, $$ } = this;
if ($$set && !is_empty($$props)) {
$$.skip_bound = true;
$$set($$props);
$$.skip_bound = false;
}
}
};
@ -222,7 +227,8 @@ export class SvelteComponent {
}
$on(type, callback) {
const callbacks = (this.$$.callbacks[type] || (this.$$.callbacks[type] = []));
const { $$ } = this;
const callbacks = ($$.callbacks[type] || ($$.callbacks[type] = []));
callbacks.push(callback);
return () => {
@ -232,10 +238,11 @@ export class SvelteComponent {
}
$set($$props) {
if (this.$$set && !is_empty($$props)) {
this.$$.skip_bound = true;
this.$$set($$props);
this.$$.skip_bound = false;
const { $$set, $$ } = this;
if ($$set && !is_empty($$props)) {
$$.skip_bound = true;
$$set($$props);
$$.skip_bound = false;
}
}
}

@ -78,12 +78,13 @@ export function flush() {
}
function update($$) {
if ($$.fragment !== null) {
const { fragment } = $$;
if (fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
fragment && fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}

@ -64,8 +64,8 @@ export function get_store_value<T>(store: Readable<T>): T {
return value;
}
export function component_subscribe(component, store, callback) {
component.$$.on_destroy.push(subscribe(store, callback));
export function component_subscribe({ $$ }, store, callback) {
$$.on_destroy.push(subscribe(store, callback));
}
export function create_slot(definition, ctx, $$scope, fn) {

Loading…
Cancel
Save