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

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

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

Loading…
Cancel
Save