|
|
@ -9,7 +9,9 @@ export function bind(component, name, callback) {
|
|
|
|
callback(component.$$.get()[name]);
|
|
|
|
callback(component.$$.get()[name]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function mount_component({ $$: { fragment }}, target, anchor, hydrate) {
|
|
|
|
export function mount_component(component, target, anchor, hydrate) {
|
|
|
|
|
|
|
|
const { fragment, refs, inject_refs, on_mount, on_destroy, after_render } = component.$$;
|
|
|
|
|
|
|
|
|
|
|
|
if (hydrate) {
|
|
|
|
if (hydrate) {
|
|
|
|
fragment.l(children(target));
|
|
|
|
fragment.l(children(target));
|
|
|
|
fragment.m(target, anchor); // TODO can we avoid moving DOM?
|
|
|
|
fragment.m(target, anchor); // TODO can we avoid moving DOM?
|
|
|
@ -18,24 +20,24 @@ export function mount_component({ $$: { fragment }}, target, anchor, hydrate) {
|
|
|
|
fragment[fragment.i ? 'i' : 'm'](target, anchor);
|
|
|
|
fragment[fragment.i ? 'i' : 'm'](target, anchor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
component.$$.inject_refs(component.$$.refs);
|
|
|
|
inject_refs(refs);
|
|
|
|
|
|
|
|
|
|
|
|
// onMount happens after the initial afterUpdate. Because
|
|
|
|
// onMount happens after the initial afterUpdate. Because
|
|
|
|
// afterUpdate callbacks happen in reverse order (inner first)
|
|
|
|
// afterUpdate callbacks happen in reverse order (inner first)
|
|
|
|
// we schedule onMount callbacks before afterUpdate callbacks
|
|
|
|
// we schedule onMount callbacks before afterUpdate callbacks
|
|
|
|
add_render_callback(() => {
|
|
|
|
add_render_callback(() => {
|
|
|
|
const onDestroy = component.$$.on_mount.map(run).filter(is_function);
|
|
|
|
const new_on_destroy = on_mount.map(run).filter(is_function);
|
|
|
|
if (component.$$.on_destroy) {
|
|
|
|
if (on_destroy) {
|
|
|
|
component.$$.on_destroy.push(...onDestroy);
|
|
|
|
on_destroy.push(...new_on_destroy);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Edge case — component was destroyed immediately,
|
|
|
|
// Edge case — component was destroyed immediately,
|
|
|
|
// most likely as a result of a binding initialising
|
|
|
|
// most likely as a result of a binding initialising
|
|
|
|
run_all(onDestroy);
|
|
|
|
run_all(new_on_destroy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
component.$$.on_mount = [];
|
|
|
|
component.$$.on_mount = [];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
component.$$.after_render.forEach(add_render_callback);
|
|
|
|
after_render.forEach(add_render_callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function destroy(component, detach) {
|
|
|
|
function destroy(component, detach) {
|
|
|
@ -58,12 +60,11 @@ function make_dirty(component, key) {
|
|
|
|
component.$$.dirty[key] = true;
|
|
|
|
component.$$.dirty[key] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class $$Component {
|
|
|
|
export function init(component, options, define, create_fragment, not_equal) {
|
|
|
|
constructor(options, init, create_fragment, not_equal) {
|
|
|
|
|
|
|
|
const previous_component = current_component;
|
|
|
|
const previous_component = current_component;
|
|
|
|
set_current_component(this);
|
|
|
|
set_current_component(component);
|
|
|
|
|
|
|
|
|
|
|
|
this.$$ = {
|
|
|
|
component.$$ = {
|
|
|
|
fragment: null,
|
|
|
|
fragment: null,
|
|
|
|
|
|
|
|
|
|
|
|
// state
|
|
|
|
// state
|
|
|
@ -87,28 +88,29 @@ export class $$Component {
|
|
|
|
binding_groups: []
|
|
|
|
binding_groups: []
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
init(this, key => {
|
|
|
|
define(component, key => {
|
|
|
|
make_dirty(this, key);
|
|
|
|
make_dirty(component, key);
|
|
|
|
if (this.$$.bound[key]) this.$$.bound[key](this.$$.get()[key]);
|
|
|
|
if (component.$$.bound[key]) component.$$.bound[key](component.$$.get()[key]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (options.props) {
|
|
|
|
if (options.props) {
|
|
|
|
this.$$.set(options.props);
|
|
|
|
component.$$.set(options.props);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
run_all(this.$$.before_render);
|
|
|
|
run_all(component.$$.before_render);
|
|
|
|
this.$$.fragment = create_fragment(this, this.$$.get());
|
|
|
|
component.$$.fragment = create_fragment(component, component.$$.get());
|
|
|
|
|
|
|
|
|
|
|
|
if (options.target) {
|
|
|
|
if (options.target) {
|
|
|
|
intro.enabled = !!options.intro;
|
|
|
|
intro.enabled = !!options.intro;
|
|
|
|
mount_component(this, options.target, options.anchor, options.hydrate);
|
|
|
|
mount_component(component, options.target, options.anchor, options.hydrate);
|
|
|
|
flush();
|
|
|
|
flush();
|
|
|
|
intro.enabled = true;
|
|
|
|
intro.enabled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set_current_component(previous_component);
|
|
|
|
set_current_component(previous_component);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class $$Component {
|
|
|
|
$destroy() {
|
|
|
|
$destroy() {
|
|
|
|
destroy(this, true);
|
|
|
|
destroy(this, true);
|
|
|
|
this.$destroy = noop;
|
|
|
|
this.$destroy = noop;
|
|
|
@ -141,8 +143,7 @@ export class $$ComponentDev extends $$Component {
|
|
|
|
throw new Error(`'target' is a required option`);
|
|
|
|
throw new Error(`'target' is a required option`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
super(...arguments);
|
|
|
|
super();
|
|
|
|
this.$$checkProps();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$destroy() {
|
|
|
|
$destroy() {
|
|
|
@ -151,8 +152,4 @@ export class $$ComponentDev extends $$Component {
|
|
|
|
console.warn(`Component was already destroyed`);
|
|
|
|
console.warn(`Component was already destroyed`);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$$checkProps() {
|
|
|
|
|
|
|
|
// noop by default
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|